diff options
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | gtk/ScintillaGTKAccessible.cxx | 7 | ||||
-rw-r--r-- | gtk/ScintillaGTKAccessible.h | 16 |
3 files changed, 27 insertions, 1 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index c63563c7f..ab03e7f3e 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -545,6 +545,11 @@ <a href="http://sourceforge.net/p/scintilla/bugs/1915/">Bug #1915</a>. </li> <li> + Improved speed of accessibility code on GTK+ by using additional memory + as a cache. + <a href="http://sourceforge.net/p/scintilla/bugs/1910/">Bug #1910</a>. + </li> + <li> Fix crash in accessibility code on GTK+ < 3.3.6 caused by previous bug fix. <a href="http://sourceforge.net/p/scintilla/bugs/1907/">Bug #1907</a>. </li> diff --git a/gtk/ScintillaGTKAccessible.cxx b/gtk/ScintillaGTKAccessible.cxx index 948b19575..11966bf20 100644 --- a/gtk/ScintillaGTKAccessible.cxx +++ b/gtk/ScintillaGTKAccessible.cxx @@ -856,6 +856,13 @@ void ScintillaGTKAccessible::NotifyReadOnly() { void ScintillaGTKAccessible::Notify(GtkWidget *, gint, SCNotification *nt) { switch (nt->nmhdr.code) { case SCN_MODIFIED: { + if (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) { + // invalidate character offset cache if applicable + const Position line = sci->pdoc->LineFromPosition(nt->position); + if (character_offsets.size() > static_cast<size_t>(line + 1)) { + character_offsets.resize(line + 1); + } + } if (nt->modificationType & SC_MOD_INSERTTEXT) { int startChar = CharacterOffsetFromByteOffset(nt->position); int lengthChar = sci->pdoc->CountCharacters(nt->position, nt->position + nt->length); diff --git a/gtk/ScintillaGTKAccessible.h b/gtk/ScintillaGTKAccessible.h index fa9698417..88256e0ca 100644 --- a/gtk/ScintillaGTKAccessible.h +++ b/gtk/ScintillaGTKAccessible.h @@ -20,6 +20,9 @@ private: GtkAccessible *accessible; ScintillaGTK *sci; + // cache holding character offset for each line start, see CharacterOffsetFromByteOffset() + std::vector<Position> character_offsets; + // cached length of the deletion, in characters (see Notify()) int deletionLengthChar; // local state for comparing @@ -52,7 +55,18 @@ private: } int CharacterOffsetFromByteOffset(Position byteOffset) { - return sci->pdoc->CountCharacters(0, byteOffset); + const Position line = sci->pdoc->LineFromPosition(byteOffset); + if (character_offsets.size() <= static_cast<size_t>(line)) { + if (character_offsets.empty()) + character_offsets.push_back(0); + for (Position i = character_offsets.size(); i <= line; i++) { + const Position start = sci->pdoc->LineStart(i - 1); + const Position end = sci->pdoc->LineStart(i); + character_offsets.push_back(character_offsets[i - 1] + sci->pdoc->CountCharacters(start, end)); + } + } + const Position lineStart = sci->pdoc->LineStart(line); + return character_offsets[line] + sci->pdoc->CountCharacters(lineStart, byteOffset); } void CharacterRangeFromByteRange(Position startByte, Position endByte, int *startChar, int *endChar) { |