From 6c345e907b046016642782d09acd27ca3ad5f91f Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 7 Feb 2022 20:12:45 +0100 Subject: [PATCH] Optimize setting image call in auto-completion In PR #11088 the calling scinitilla is not optimized: SCI_REGISTERIMAGE & SCI_AUTOCSETTYPESEPARATOR need to be called only once. --- .../src/ScintillaComponent/AutoCompletion.cpp | 19 ++++++++++++------- .../src/ScintillaComponent/AutoCompletion.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp index 77f3cee65..e8708e45d 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp @@ -117,9 +117,13 @@ bool AutoCompletion::showApiComplete() if (len >= _keyWordMaxLen) return false; + if (!_isFxImageRegistered) + { + _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('?')); + _pEditView->execute(SCI_REGISTERIMAGE, FUNC_IMG_ID, LPARAM(xpmfn)); + _isFxImageRegistered = true; + } _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); - _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('?')); - _pEditView->execute(SCI_REGISTERIMAGE, FUNC_IMG_ID, LPARAM(xpmfn)); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, _keyWords.c_str()); @@ -202,10 +206,13 @@ bool AutoCompletion::showApiAndWordComplete() } // Make Scintilla show the autocompletion menu - + if (!_isFxImageRegistered) + { + _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('?')); + _pEditView->execute(SCI_REGISTERIMAGE, FUNC_IMG_ID, LPARAM(xpmfn)); + _isFxImageRegistered = true; + } _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); - _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('?')); - _pEditView->execute(SCI_REGISTERIMAGE, FUNC_IMG_ID, LPARAM(xpmfn)); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, words.c_str()); return true; @@ -464,8 +471,6 @@ bool AutoCompletion::showWordComplete(bool autoInsert) // Make Scintilla show the autocompletion menu _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); - _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('?')); - _pEditView->execute(SCI_REGISTERIMAGE, FUNC_IMG_ID, LPARAM(xpmfn)); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, words.c_str()); return true; diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.h b/PowerEditor/src/ScintillaComponent/AutoCompletion.h index 6b0eb0f3a..44fe75290 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.h +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.h @@ -79,6 +79,7 @@ private: LangType _curLang = L_TEXT; TiXmlDocument *_pXmlFile = nullptr; TiXmlElement *_pXmlKeyword = nullptr; + bool _isFxImageRegistered = false; InsertedMatchedChars _insertedMatchedChars;