From 9178fc168a97fdf49fdf828c6d785b49421ca032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 2 Sep 2020 00:40:57 -0300 Subject: [PATCH] Bug fix in ProjectSearch (ecode). Minor fxi in UITreeViewGlobalSearch results. Fix in the UITextInput text input. --- include/eepp/ui/doc/syntaxtokenizer.hpp | 3 +- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 3 +- src/eepp/ui/doc/syntaxtokenizer.cpp | 5 +-- src/eepp/ui/uitextinput.cpp | 31 +++++++++---------- src/tools/codeeditor/codeeditor.cpp | 8 ++++- src/tools/codeeditor/projectsearch.cpp | 12 ++++--- .../codeeditor/uitreeviewglobalsearch.cpp | 22 +++++++------ .../codeeditor/uitreeviewglobalsearch.hpp | 2 +- 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/include/eepp/ui/doc/syntaxtokenizer.hpp b/include/eepp/ui/doc/syntaxtokenizer.hpp index 39deff32c..db26377e2 100644 --- a/include/eepp/ui/doc/syntaxtokenizer.hpp +++ b/include/eepp/ui/doc/syntaxtokenizer.hpp @@ -19,7 +19,8 @@ class EE_API SyntaxTokenizer { public: std::pair, int> static tokenize( const SyntaxDefinition& syntax, const std::string& text, - const int& state ); + const int& state, + const size_t& startIndex = 0 ); }; }}} // namespace EE::UI::Doc diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index e34b15cd9..4f31db068 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -260,8 +260,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {{"-?%.?%d+f?"}, "number"}, {{"[%+%-=/%*%^%%<>!~|&]"}, "operator"}, {{"[%a_][%w_]*%f[(]"}, "function"}, - {{"std%:%:[%w_]-%<.-%>"}, "keyword2"}, - {{"std%:%:.-%s"}, "keyword2"}, + {{"std%:%:[%w_]*"}, "keyword2"}, {{"[%a_][%w_]*"}, "symbol"}, }, { diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 974de57de..41b2b0c02 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -58,14 +58,15 @@ std::pair findNonEscaped( const std::string& text, const std::string& std::pair, int> SyntaxTokenizer::tokenize( const SyntaxDefinition& syntax, const std::string& text, - const int& state ) { + const int& state, + const size_t& startIndex ) { std::vector tokens; if ( syntax.getPatterns().empty() ) { pushToken( tokens, "normal", text ); return std::make_pair( tokens, SYNTAX_TOKENIZER_STATE_NONE ); } - size_t i = 0; + size_t i = startIndex; int retState = state; while ( i < text.size() ) { diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index adeb7d538..714f846cf 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -734,26 +734,23 @@ Uint32 UITextInput::onTextInput( const TextInputEvent& event ) { return 0; Input* input = getUISceneNode()->getWindow()->getInput(); - if ( !input->isControlPressed() && !( input->isAltPressed() && input->isShiftPressed() ) ) { - if ( input->isAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) + if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || + ( input->isLeftAltPressed() && input->isShiftPressed() ) || input->isControlPressed() ) + return 0; + + const String& text = event.getText(); + + for ( size_t i = 0; i < text.size(); i++ ) { + if ( text[i] == '\n' ) + return 0; + if ( mOnlyNumbers && ( ( mAllowFloat && text[i] == '.' && mDoc.find( "." ).isValid() ) || + !String::isNumber( text[i], mAllowFloat ) ) ) { return 0; - - const String& text = event.getText(); - - for ( size_t i = 0; i < text.size(); i++ ) { - if ( text[i] == '\n' ) - return 0; - if ( mOnlyNumbers && - ( ( mAllowFloat && text[i] == '.' && mDoc.find( "." ).isValid() ) || - !String::isNumber( text[i], mAllowFloat ) ) ) { - return 0; - } } - - mDoc.textInput( text ); - return 1; } - return 0; + + mDoc.textInput( text ); + return 1; } void UITextInput::setAllowOnlyNumbers( const bool& onlyNumbers, const bool& allowFloat ) { diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index e33cafebe..08170ca15 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -723,6 +723,9 @@ void App::showGlobalSearch() { mEditorSplitter->getCurEditor()->getDocument().getSelectedText() ); } mGlobalSearchInput->getDocument().selectAll(); + auto* loader = mGlobalSearchTree->getParent()->find( "loader" ); + if ( loader ) + loader->setVisible( true ); updateGlobalSearchBar(); } @@ -742,6 +745,9 @@ void App::updateGlobalSearchBar() { void App::hideGlobalSearchBar() { mGlobalSearchBarLayout->setEnabled( false )->setVisible( false ); mGlobalSearchTree->setVisible( false ); + auto* loader = mGlobalSearchTree->getParent()->find( "loader" ); + if ( loader ) + loader->setVisible( false ); } void App::initGlobalSearchBar() { @@ -759,7 +765,7 @@ void App::initGlobalSearchBar() { mGlobalSearchBarLayout->addCommand( "search-in-files", [&, caseSensitiveChk] { if ( mDirTree && mDirTree->getFilesCount() > 0 && !mGlobalSearchInput->getText().empty() ) { UILoader* loader = UILoader::New(); - loader->setId( "loader " ); + loader->setId( "loader" ); loader->setRadius( 48 ); loader->setOutlineThickness( 6 ); loader->setFillColor( Color::Red ); diff --git a/src/tools/codeeditor/projectsearch.cpp b/src/tools/codeeditor/projectsearch.cpp index 657ee35f1..5ab942c58 100644 --- a/src/tools/codeeditor/projectsearch.cpp +++ b/src/tools/codeeditor/projectsearch.cpp @@ -5,10 +5,12 @@ static int countNewLines( const std::string& text, const size_t& start, const si const char* startPtr = text.c_str() + start; const char* endPtr = text.c_str() + end; size_t count = 0; - do { - if ( '\n' == *startPtr ) - count++; - } while ( ++startPtr && startPtr != endPtr ); + if ( startPtr != endPtr ) { + while ( ++startPtr && startPtr != endPtr ) { + if ( '\n' == *startPtr ) + count++; + } ; + } return count; } @@ -23,7 +25,7 @@ static std::string textLine( const std::string& fileText, const size_t& fromPos, const char* nlStartPtr = ptr + 1; start = ptr - stringStartPtr + 1; ptr = startPtr; - while ( ++ptr && *ptr != '\n' ) { + while ( ++ptr && *ptr != '\0' && *ptr != '\n' ) { } end = ptr - stringStartPtr; relCol = startPtr - nlStartPtr; diff --git a/src/tools/codeeditor/uitreeviewglobalsearch.cpp b/src/tools/codeeditor/uitreeviewglobalsearch.cpp index 1c5724727..0121d00e0 100644 --- a/src/tools/codeeditor/uitreeviewglobalsearch.cpp +++ b/src/tools/codeeditor/uitreeviewglobalsearch.cpp @@ -21,13 +21,13 @@ UIPushButton* UITreeViewCellGlobalSearch::setText( const String& text ) { if ( text != mTextBox->getText() ) { mTextBox->setVisible( !text.empty() ); mTextBox->setText( text ); - updateText( text ); + updateText( text + '\n' ); updateLayout(); } return this; } -UIPushButton* UITreeViewCellGlobalSearch::updateText( const String& text ) { +UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) { if ( getCurIndex().internalId() != -1 ) { UITreeViewGlobalSearch* pp = getParent()->getParent()->asType(); @@ -35,20 +35,22 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const String& text ) { auto styleDef = SyntaxDefinitionManager::instance()->getStyleByExtension( res->file ); - auto tokens = - SyntaxTokenizer::tokenize( styleDef, text, SYNTAX_TOKENIZER_STATE_NONE ).first; + Uint32 from = text.find_first_not_of( ' ' ); + Uint32 to = from; + if ( from != String::InvalidPos ) { + to = text.find_first_of( ' ', from ); + mTextBox->setFontFillColor( pp->getLineNumColor(), from, to ); + } - size_t start = 0; + auto tokens = + SyntaxTokenizer::tokenize( styleDef, text, SYNTAX_TOKENIZER_STATE_NONE, to ).first; + + size_t start = to; for ( auto& token : tokens ) { mTextBox->setFontFillColor( pp->getColorScheme().getSyntaxStyle( token.type ).color, start, start + token.text.size() ); start += token.text.size(); } - - Uint32 from = text.find_first_not_of( ' ' ); - if ( from != String::InvalidPos ) - mTextBox->setFontFillColor( pp->getLineNumColor(), from, - text.find_first_of( ' ', from ) ); } return this; } diff --git a/src/tools/codeeditor/uitreeviewglobalsearch.hpp b/src/tools/codeeditor/uitreeviewglobalsearch.hpp index f3e35eceb..f84a16189 100644 --- a/src/tools/codeeditor/uitreeviewglobalsearch.hpp +++ b/src/tools/codeeditor/uitreeviewglobalsearch.hpp @@ -16,7 +16,7 @@ class UITreeViewCellGlobalSearch : public UITreeViewCell { UIPushButton* setText( const String& text ); - UIPushButton* updateText( const String& text ); + UIPushButton* updateText( const std::string& text ); }; class UITreeViewGlobalSearch : public UITreeView {