[geany/geany-plugins] e8507d: geanylatex: fix automatic capitalization of multi-byte characters

Colomban Wendling git-noreply at xxxxx
Sat Apr 12 17:56:32 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 12 Apr 2014 17:56:32 UTC
Commit:      e8507d1c2438872d6b748d258a1d75ec394e8452
             https://github.com/geany/geany-plugins/commit/e8507d1c2438872d6b748d258a1d75ec394e8452

Log Message:
-----------
geanylatex: fix automatic capitalization of multi-byte characters

Fix indexing relative document positions by characters, not bytes, when
performing automatic capitalization of sentence start.

Geany API dependency is bumped to 217.  Even though this change doesn't
actually require new API introduced by this version, it requires
Scintilla 3.3.5 which is only available in Geany 1.24, and API 217 is
the closest one to this.


Modified Paths:
--------------
    geanylatex/src/geanylatex.c

Modified: geanylatex/src/geanylatex.c
24 files changed, 18 insertions(+), 6 deletions(-)
===================================================================
@@ -33,7 +33,7 @@
 #include "geanylatex.h"
 #include "ctype.h"
 
-PLUGIN_VERSION_CHECK(199)
+PLUGIN_VERSION_CHECK(217)
 
 PLUGIN_SET_TRANSLATABLE_INFO(
 	LOCALEDIR,
@@ -501,6 +501,18 @@ static void on_document_filetype_set(G_GNUC_UNUSED GObject *obj, GeanyDocument *
 }
 
 
+static gint get_position_relative(ScintillaObject *sci, gint pos, gint n)
+{
+	return (gint) scintilla_send_message(sci, SCI_POSITIONRELATIVE, (uptr_t) pos, n);
+}
+
+
+static gint get_char_relative(ScintillaObject *sci, gint pos, gint n)
+{
+	return sci_get_char_at(sci, get_position_relative(sci, pos, n));
+}
+
+
 static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *editor,
 									SCNotification *nt, G_GNUC_UNUSED gpointer data)
 {
@@ -690,15 +702,15 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi
 				{
 					if (glatex_capitalize_sentence_starts == TRUE)
 					{
-						if (sci_get_char_at(sci, pos -2) == ' ' &&
-							(sci_get_char_at(sci, pos -3) == '.' ||
-							 sci_get_char_at(sci, pos -3) == '!' ||
-							 sci_get_char_at(sci, pos -3) == '?' ))
+						if (get_char_relative(sci, pos, -2) == ' ' &&
+							(get_char_relative(sci, pos, -3) == '.' ||
+							 get_char_relative(sci, pos, -3) == '!' ||
+							 get_char_relative(sci, pos, -3) == '?'))
 						{
 							gchar *upperLtr = NULL;
 							gchar *selection = NULL;
 
-							sci_set_selection_start(sci, pos - 1);
+							sci_set_selection_start(sci, get_position_relative(sci, pos, -1));
 							sci_set_selection_end(sci, pos);
 
 							selection = sci_get_selection_contents(sci);



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


More information about the Plugins-Commits mailing list