aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/ScintillaGTKAccessible.h
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2019-04-05 14:06:48 +0200
committerColomban Wendling <ban@herbesfolles.org>2019-04-05 14:06:48 +0200
commitca6ad60c453ecc2a79458c24dc38a1b46d55cf8b (patch)
tree859179d242083296937f19eea60bc2a8a4333044 /gtk/ScintillaGTKAccessible.h
parent49ce685da58519c39ab5de8aafe5c9fbedcbd5e1 (diff)
downloadscintilla-mirror-ca6ad60c453ecc2a79458c24dc38a1b46d55cf8b.tar.gz
Backport: Bug [#2094]. gtk: Accessible: use the built-in character position cache
It's quite a lot faster even after trying and optimizing the custom version, and it makes the code simpler. Also improve ByteOffsetFromCharacterOffset() to make use of the cache, making it drastically faster. Backport of changeset 7405:01aab5f24e50.
Diffstat (limited to 'gtk/ScintillaGTKAccessible.h')
-rw-r--r--gtk/ScintillaGTKAccessible.h26
1 files changed, 12 insertions, 14 deletions
diff --git a/gtk/ScintillaGTKAccessible.h b/gtk/ScintillaGTKAccessible.h
index 2c39d5257..00570acce 100644
--- a/gtk/ScintillaGTKAccessible.h
+++ b/gtk/ScintillaGTKAccessible.h
@@ -18,9 +18,6 @@ private:
GtkAccessible *accessible;
ScintillaGTK *sci;
- // cache holding character offset for each line start, see CharacterOffsetFromByteOffset()
- std::vector<Sci::Position> character_offsets;
-
// cached length of the deletion, in characters (see Notify())
int deletionLengthChar;
// local state for comparing
@@ -37,6 +34,16 @@ private:
}
Sci::Position ByteOffsetFromCharacterOffset(Sci::Position startByte, int characterOffset) {
+ if (characterOffset > 0) {
+ // Try and reduce the range by reverse-looking into the character offset cache
+ Sci::Line lineStart = sci->pdoc->LineFromPosition(startByte);
+ Sci::Position posStart = sci->pdoc->IndexLineStart(lineStart, SC_LINECHARACTERINDEX_UTF32);
+ Sci::Line line = sci->pdoc->LineFromPositionIndex(posStart + characterOffset, SC_LINECHARACTERINDEX_UTF32);
+ if (line != lineStart) {
+ startByte += sci->pdoc->LineStart(line) - sci->pdoc->LineStart(lineStart);
+ characterOffset -= sci->pdoc->IndexLineStart(line, SC_LINECHARACTERINDEX_UTF32) - posStart;
+ }
+ }
Sci::Position pos = sci->pdoc->GetRelativePosition(startByte, characterOffset);
if (pos == INVALID_POSITION) {
// clamp invalid positions inside the document
@@ -55,17 +62,8 @@ private:
Sci::Position CharacterOffsetFromByteOffset(Sci::Position byteOffset) {
const Sci::Line line = sci->pdoc->LineFromPosition(byteOffset);
- if (character_offsets.size() <= static_cast<size_t>(line)) {
- if (character_offsets.empty())
- character_offsets.push_back(0);
- for (Sci::Position i = character_offsets.size(); i <= line; i++) {
- const Sci::Position start = sci->pdoc->LineStart(i - 1);
- const Sci::Position end = sci->pdoc->LineStart(i);
- character_offsets.push_back(character_offsets[i - 1] + sci->pdoc->CountCharacters(start, end));
- }
- }
const Sci::Position lineStart = sci->pdoc->LineStart(line);
- return character_offsets[line] + sci->pdoc->CountCharacters(lineStart, byteOffset);
+ return sci->pdoc->IndexLineStart(line, SC_LINECHARACTERINDEX_UTF32) + sci->pdoc->CountCharacters(lineStart, byteOffset);
}
void CharacterRangeFromByteRange(Sci::Position startByte, Sci::Position endByte, int *startChar, int *endChar) {
@@ -135,7 +133,7 @@ public:
// So ScintillaGTK can notify us
void ChangeDocument(Document *oldDoc, Document *newDoc);
void NotifyReadOnly();
- void SetAccessibility();
+ void SetAccessibility(bool enabled);
// Helper GtkWidget methods
static AtkObject *WidgetGetAccessibleImpl(GtkWidget *widget, AtkObject **cache, gpointer widget_parent_class);