[geany/geany-plugins] 3af500: Automark: remove global vars, simple search, disable plugin while selection

Pavel Roschin git-noreply at xxxxx
Sat Sep 6 18:33:51 UTC 2014


Branch:      refs/heads/master
Author:      Pavel Roschin <roshin at scriptumplus.ru>
Committer:   Pavel Roschin <roshin at scriptumplus.ru>
Date:        Sat, 06 Sep 2014 18:33:51 UTC
Commit:      3af5005bdce6f93db89d27a1638cb7e73496b7d8
             https://github.com/geany/geany-plugins/commit/3af5005bdce6f93db89d27a1638cb7e73496b7d8

Log Message:
-----------
Automark: remove global vars, simple search, disable plugin while selection


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

Modified: automark/src/automark.c
37 lines changed, 22 insertions(+), 15 deletions(-)
===================================================================
@@ -51,8 +51,6 @@ PLUGIN_SET_TRANSLATABLE_INFO(
 	"Pavel Roschin <rpg89(at)post(dot)ru>")
 
 static gint source_id;
-static gchar text_cache[GEANY_MAX_WORD_LENGTH] = {0};
-static GeanyEditor *editor_cache = NULL;
 
 static const gint AUTOMARK_INDICATOR = GEANY_INDICATOR_SEARCH;
 
@@ -62,7 +60,9 @@ search_mark_in_range(
 	gint         flags,
 	struct       Sci_TextToFind *ttf)
 {
-	while (SSM(editor->sci, SCI_FINDTEXT, flags, (uptr_t)ttf) != -1)
+	ScintillaObject *sci = editor->sci;
+
+	while (SSM(sci, SCI_FINDTEXT, flags, (uptr_t)ttf) != -1)
 	{
 		gint start = ttf->chrgText.cpMin;
 		gint end = ttf->chrgText.cpMax;
@@ -71,11 +71,12 @@ search_mark_in_range(
 			break;
 
 		ttf->chrg.cpMin = ttf->chrgText.cpMax;
-		if (end != start)
-		{
-			SSM(editor->sci, SCI_SETINDICATORCURRENT, AUTOMARK_INDICATOR, 0);
-			SSM(editor->sci, SCI_INDICATORFILLRANGE, start, end - start);
-		}
+		if (end == start)
+			continue;
+		if(SSM(sci, SCI_INDICATORVALUEAT, AUTOMARK_INDICATOR, start))
+			continue;
+		SSM(sci, SCI_SETINDICATORCURRENT, AUTOMARK_INDICATOR, 0);
+		SSM(sci, SCI_INDICATORFILLRANGE, start, end - start);
 	}
 }
 
@@ -86,7 +87,7 @@ get_current_word(ScintillaObject *sci, gchar *word, gsize wordlen)
 	gint pos = sci_get_current_position(sci);
 	gint start = SSM(sci, SCI_WORDSTARTPOSITION, pos, TRUE);
 	gint end = SSM(sci, SCI_WORDENDPOSITION, pos, TRUE);
-
+	
 	if (start == end)
 		*word = 0;
 	else
@@ -100,12 +101,14 @@ get_current_word(ScintillaObject *sci, gchar *word, gsize wordlen)
 static gboolean
 automark(gpointer user_data)
 {
-	GeanyDocument   *doc = (GeanyDocument *)user_data;
-	GeanyEditor     *editor = doc->editor;
-	ScintillaObject *sci = editor->sci;
-	gchar            text[GEANY_MAX_WORD_LENGTH];
-	gint             match_flag = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
-	struct           Sci_TextToFind ttf;
+	GeanyDocument      *doc = (GeanyDocument *)user_data;
+	GeanyEditor        *editor = doc->editor;
+	static GeanyEditor *editor_cache = NULL;
+	ScintillaObject    *sci = editor->sci;
+	gchar               text[GEANY_MAX_WORD_LENGTH];
+	static gchar        text_cache[GEANY_MAX_WORD_LENGTH] = {0};
+	gint                match_flag = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
+	struct              Sci_TextToFind ttf;
 
 	source_id = 0;
 
@@ -113,6 +116,10 @@ automark(gpointer user_data)
 	if (!DOC_VALID(doc))
 		return FALSE;
 
+	/* Do not highlight while selecting text and allow other markers to work */
+	if (sci_has_selection(sci))
+		return FALSE;
+
 	get_current_word(editor->sci, text, sizeof(text));
 
 	if (!*text)



--------------
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