aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2016-12-18 16:35:22 +0100
committerColomban Wendling <ban@herbesfolles.org>2016-12-18 16:35:22 +0100
commit6ec638201f5600dd24dcaaf580c499200fdbddbe (patch)
tree6569a4c565bc1ee3043983c1b779e031676f29da
parenta19969b8cc1d1de3d8119e831a8e017dd256361e (diff)
downloadscintilla-mirror-6ec638201f5600dd24dcaaf580c499200fdbddbe.tar.gz
GTK: Fix reporting deletion length in the accessible
We cannot compute the length in characters after the text has been deleted, so we need to compute it in BEFOREDELETE. However, we need to emit the signal once the buffer has actually changed, so we need to cache the value in-between those events.
-rw-r--r--gtk/ScintillaGTKAccessible.cxx10
-rw-r--r--gtk/ScintillaGTKAccessible.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/gtk/ScintillaGTKAccessible.cxx b/gtk/ScintillaGTKAccessible.cxx
index 137b1cd82..3fdb22828 100644
--- a/gtk/ScintillaGTKAccessible.cxx
+++ b/gtk/ScintillaGTKAccessible.cxx
@@ -156,6 +156,7 @@ ScintillaGTKAccessible *ScintillaGTKAccessible::FromAccessible(GtkAccessible *ac
ScintillaGTKAccessible::ScintillaGTKAccessible(GtkAccessible *accessible_, GtkWidget *widget_) :
accessible(accessible_),
sci(ScintillaGTK::FromWidget(widget_)),
+ deletionLengthChar(0),
old_pos(-1) {
g_signal_connect(widget_, "sci-notify", G_CALLBACK(SciNotify), this);
}
@@ -857,10 +858,15 @@ void ScintillaGTKAccessible::Notify(GtkWidget *, gint, SCNotification *nt) {
g_signal_emit_by_name(accessible, "text-changed::insert", startChar, lengthChar);
UpdateCursor();
}
+ if (nt->modificationType & SC_MOD_BEFOREDELETE) {
+ // We cannot compute the deletion length in DELETETEXT as it requires accessing the
+ // buffer, so that the character are still present. So, we cache the value here,
+ // and use it in DELETETEXT that fires quickly after.
+ deletionLengthChar = sci->pdoc->CountCharacters(nt->position, nt->position + nt->length);
+ }
if (nt->modificationType & SC_MOD_DELETETEXT) {
int startChar = CharacterOffsetFromByteOffset(nt->position);
- int lengthChar = sci->pdoc->CountCharacters(nt->position, nt->position + nt->length);
- g_signal_emit_by_name(accessible, "text-changed::delete", startChar, lengthChar);
+ g_signal_emit_by_name(accessible, "text-changed::delete", startChar, deletionLengthChar);
UpdateCursor();
}
if (nt->modificationType & SC_MOD_CHANGESTYLE) {
diff --git a/gtk/ScintillaGTKAccessible.h b/gtk/ScintillaGTKAccessible.h
index 93883025d..94430636b 100644
--- a/gtk/ScintillaGTKAccessible.h
+++ b/gtk/ScintillaGTKAccessible.h
@@ -20,6 +20,8 @@ private:
GtkAccessible *accessible;
ScintillaGTK *sci;
+ // cached length of the deletion, in characters (see Notify())
+ int deletionLengthChar;
// local state for comparing
Position old_pos;
std::vector<SelectionRange> old_sels;