aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/ScintillaGTKAccessible.cxx
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2017-02-21 22:30:05 +0100
committerColomban Wendling <ban@herbesfolles.org>2017-02-21 22:30:05 +0100
commit0cf093422878653e174d57c0c02ffe4880c6be7a (patch)
treeda29e1780e99ffd0f1cd97149542cff24766d99c /gtk/ScintillaGTKAccessible.cxx
parent14c9bcc7dc7d5a8577136baad5b43c6bc311312d (diff)
downloadscintilla-mirror-0cf093422878653e174d57c0c02ffe4880c6be7a.tar.gz
Bug [#1910]. GTK a11y: Speed up converting byte offsets to character offsets
Use a per-line cache to avoid re-computing the offset from the start of the buffer each time. This dramatically speeds up multiple replacements on large files.
Diffstat (limited to 'gtk/ScintillaGTKAccessible.cxx')
-rw-r--r--gtk/ScintillaGTKAccessible.cxx7
1 files changed, 7 insertions, 0 deletions
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);