From 999b1cfa7b6c50fd008ef4693c1da034fc83eddd Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Tue, 21 Nov 2017 21:33:41 -0800 Subject: [PATCH] Improve smart highlighting performance Abort highlight search if the selection crosses a line boundry. Closes #3908 --- .../src/ScitillaComponent/SmartHighlighter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp index f61e23f9..9ae9605e 100644 --- a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp @@ -127,6 +127,7 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView, Scintil auto curPos = pHighlightView->execute(SCI_GETCURRENTPOS); auto range = pHighlightView->getSelection(); + int textlen = range.cpMax - range.cpMin + 1; // Determine mode for SmartHighlighting bool isWordOnly = true; @@ -153,8 +154,14 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView, Scintil if (wordStart == wordEnd || wordStart != range.cpMin || wordEnd != range.cpMax) return; } - - int textlen = range.cpMax - range.cpMin + 1; + else + { + auto line = pHighlightView->execute(SCI_LINEFROMPOSITION, curPos); + auto lineLength = pHighlightView->execute(SCI_LINELENGTH, line); + if (textlen > lineLength) + return; + } + char * text2Find = new char[textlen]; pHighlightView->getSelectedText(text2Find, textlen, false); //do not expand selection (false)