[geany/geany] a31a43: GTK: Fix reporting deletion length in the accessible

Colomban Wendling git-noreply at xxxxx
Tue Dec 20 20:45:29 UTC 2016


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Tue, 20 Dec 2016 20:45:29 UTC
Commit:      a31a43efe15a55ea249c2224f6688c9dcf5f5b64
             https://github.com/geany/geany/commit/a31a43efe15a55ea249c2224f6688c9dcf5f5b64

Log Message:
-----------
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.


Modified Paths:
--------------
    scintilla/gtk/ScintillaGTKAccessible.cxx
    scintilla/gtk/ScintillaGTKAccessible.h

Modified: scintilla/gtk/ScintillaGTKAccessible.cxx
10 lines changed, 8 insertions(+), 2 deletions(-)
===================================================================
@@ -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) {


Modified: scintilla/gtk/ScintillaGTKAccessible.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -20,6 +20,8 @@ class ScintillaGTKAccessible {
 	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;



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list