diff --git a/src/eepp/ui/doc/syntaxhighlighter.cpp b/src/eepp/ui/doc/syntaxhighlighter.cpp index fb3a550b6..13ac1ae3c 100644 --- a/src/eepp/ui/doc/syntaxhighlighter.cpp +++ b/src/eepp/ui/doc/syntaxhighlighter.cpp @@ -56,7 +56,6 @@ TokenizedLine SyntaxHighlighter::tokenizeLine( const size_t& line, const Uint64& while ( textSize > 0 ) { size_t chunkSize = textSize > mMaxTokenizationLength ? mMaxTokenizationLength : textSize; - std::string substr = ln.substr( pos, chunkSize ); SyntaxTokenPosition token{ "normal", pos, chunkSize }; token.len = ln.size(); tokenizedLine.tokens.emplace_back( token ); @@ -86,7 +85,7 @@ void SyntaxHighlighter::moveHighlight( const Int64& fromLine, const Int64& numLi for ( Int64 i = linesCount - 1; i >= fromLine; --i ) { auto lineIt = mLines.find( i - numLines ); if ( lineIt != mLines.end() ) { - auto& line = lineIt->second; + const auto& line = lineIt->second; if ( line.hash == mDoc->line( i ).getHash() ) { auto nl = mLines.extract( lineIt ); nl.key() = i; diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index 1e0c9f233..ff47f71eb 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -418,6 +418,7 @@ void GlobalSearchController::updateGlobalSearchBarResults( const std::string& search, std::shared_ptr model, bool searchReplace, bool isEscaped ) { updateGlobalSearchBar(); + mGlobalSearchTree->hAsCPP = mApp->getProjectDocConfig().hAsCPP; mGlobalSearchTree->setSearchStr( search ); mGlobalSearchTree->setModel( model ); if ( mGlobalSearchTree->getModel()->rowCount() < 50 ) diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 4d29206bf..f1f7cdd36 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -1,5 +1,5 @@ -#include "uitreeviewglobalsearch.hpp" #include "projectsearch.hpp" +#include "uitreeviewglobalsearch.hpp" #include #include #include @@ -9,6 +9,26 @@ namespace ecode { +static Float getTextWidth( Float glyphWidth, Uint32 tabWidth, const String& line ) { + size_t len = line.length(); + Float x = 0; + for ( size_t i = 0; i < len; i++ ) + x += ( line[i] == '\t' ) ? glyphWidth * tabWidth : glyphWidth; + return x; +} + +static Float getXOffsetCol( Float glyphWidth, Uint32 tabWidth, const String& line, Int64 col ) { + Float x = 0; + for ( auto i = 0; i < col; i++ ) { + if ( line[i] == '\t' ) { + x += glyphWidth * tabWidth; + } else if ( line[i] != '\n' && line[i] != '\r' ) { + x += glyphWidth; + } + } + return x; +} + UITreeViewGlobalSearch::UITreeViewGlobalSearch( const SyntaxColorScheme& colorScheme, bool searchReplace ) : UITreeView(), @@ -19,7 +39,7 @@ UITreeViewGlobalSearch::UITreeViewGlobalSearch( const SyntaxColorScheme& colorSc UIWidget* UITreeViewGlobalSearch::createCell( UIWidget* rowWidget, const ModelIndex& index ) { UITableCell* widget = index.column() == (Int64)getModel()->treeColumn() - ? UITreeViewCellGlobalSearch::New( mSearchReplace ) + ? UITreeViewCellGlobalSearch::New( mSearchReplace, hAsCPP ) : UITableCell::New(); return setupCell( widget, rowWidget, index ); } @@ -108,8 +128,8 @@ ProjectSearch::ResultData* UITreeViewCellGlobalSearch::getResultDataPtr() { #define CELL_GLOBAL_SEARCH_PADDING ( 12 ) -UITreeViewCellGlobalSearch::UITreeViewCellGlobalSearch( bool selectionEnabled ) : - UITreeViewCell( selectionEnabled ? getCheckBoxFn() : nullptr ) {} +UITreeViewCellGlobalSearch::UITreeViewCellGlobalSearch( bool selectionEnabled, bool hAsCPP ) : + UITreeViewCell( selectionEnabled ? getCheckBoxFn() : nullptr ), mHAsCpp( hAsCPP ) {} UIPushButton* UITreeViewCellGlobalSearch::setText( const String& text ) { auto* result = getResultPtr(); @@ -133,7 +153,8 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) ProjectSearch::ResultData* res = (ProjectSearch::ResultData*)getCurIndex().parent().internalData(); - auto styleDef = SyntaxDefinitionManager::instance()->getByExtension( res->file ); + const auto& styleDef = + SyntaxDefinitionManager::instance()->getByExtension( res->file, mHAsCpp ); Uint32 from = text.find_first_not_of( ' ' ); Uint32 to = from; @@ -159,7 +180,7 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) SyntaxTokenizer::tokenize( styleDef, text, SYNTAX_TOKENIZER_STATE_NONE, to ).first; size_t start = to; - for ( auto& token : tokens ) { + for ( const auto& token : tokens ) { mTextBox->setFontFillColor( pp->getColorScheme().getSyntaxStyle( token.type ).color, start, start + token.len ); start += token.len; @@ -168,26 +189,6 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) return this; } -static Float getTextWidth( Float glyphWidth, Uint32 tabWidth, const String& line ) { - size_t len = line.length(); - Float x = 0; - for ( size_t i = 0; i < len; i++ ) - x += ( line[i] == '\t' ) ? glyphWidth * tabWidth : glyphWidth; - return x; -} - -static Float getXOffsetCol( Float glyphWidth, Uint32 tabWidth, const String& line, Int64 col ) { - Float x = 0; - for ( auto i = 0; i < col; i++ ) { - if ( line[i] == '\t' ) { - x += glyphWidth * tabWidth; - } else if ( line[i] != '\n' && line[i] != '\r' ) { - x += glyphWidth; - } - } - return x; -} - void UITreeViewCellGlobalSearch::draw() { UITreeViewCell::draw(); if ( getCurIndex().internalId() != -1 && mSearchStrPos.first != std::string::npos && diff --git a/src/tools/ecode/uitreeviewglobalsearch.hpp b/src/tools/ecode/uitreeviewglobalsearch.hpp index 886a20316..f25da1b0b 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.hpp +++ b/src/tools/ecode/uitreeviewglobalsearch.hpp @@ -12,16 +12,14 @@ namespace ecode { class UITreeViewCellGlobalSearch : public UITreeViewCell { public: - static UITreeViewCellGlobalSearch* New( bool selectionEnabled ) { - return eeNew( UITreeViewCellGlobalSearch, ( selectionEnabled ) ); + static UITreeViewCellGlobalSearch* New( bool selectionEnabled, bool hAsCPP ) { + return eeNew( UITreeViewCellGlobalSearch, ( selectionEnabled, hAsCPP ) ); } - UITreeViewCellGlobalSearch( bool selectionEnabled ); + explicit UITreeViewCellGlobalSearch( bool selectionEnabled, bool hAsCPP ); UIPushButton* setText( const String& text ); - UIPushButton* updateText( const std::string& text ); - virtual void draw(); virtual void updateCell( Model* model ); @@ -31,11 +29,14 @@ class UITreeViewCellGlobalSearch : public UITreeViewCell { protected: std::pair mSearchStrPos; String mResultStr; + bool mHAsCpp{ false }; std::function getCheckBoxFn(); void* getDataPtr( const ModelIndex& modelIndex ); + UIPushButton* updateText( const std::string& text ); + ProjectSearch::ResultData::Result* getResultPtr(); ProjectSearch::ResultData* getResultDataPtr(); @@ -61,6 +62,7 @@ class UITreeViewGlobalSearch : public UITreeView { const String& getSearchStr() const { return mSearchStr; } + bool hAsCPP = false; protected: Color mLineNumColor; SyntaxColorScheme mColorScheme;