SF.net SVN: geany-plugins:[252] trunk/spellcheck

eht16 at users.sourceforge.net eht16 at xxxxx
Sat Oct 25 15:33:03 UTC 2008


Revision: 252
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=252&view=rev
Author:   eht16
Date:     2008-10-25 15:33:03 +0000 (Sat, 25 Oct 2008)

Log Message:
-----------
When adding words to the dictionary, remove all indicators on these words.

Modified Paths:
--------------
    trunk/spellcheck/ChangeLog
    trunk/spellcheck/src/gui.c

Modified: trunk/spellcheck/ChangeLog
===================================================================
--- trunk/spellcheck/ChangeLog	2008-10-25 09:30:25 UTC (rev 251)
+++ trunk/spellcheck/ChangeLog	2008-10-25 15:33:03 UTC (rev 252)
@@ -7,6 +7,8 @@
  * src/gui.c:
    Ignore numbers when updating the editor menu.
    Rename the editor menu item to 'Spelling Suggestions'.
+   When adding words to the dictionary, remove all indicators on
+   these words.
 
 
 2008-10-17  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/spellcheck/src/gui.c
===================================================================
--- trunk/spellcheck/src/gui.c	2008-10-25 09:30:25 UTC (rev 251)
+++ trunk/spellcheck/src/gui.c	2008-10-25 15:33:03 UTC (rev 252)
@@ -27,6 +27,7 @@
 #include "support.h"
 
 #include <ctype.h>
+#include <string.h>
 
 #include "plugindata.h"
 
@@ -111,17 +112,6 @@
 }
 
 
-static void clear_indicators_on_range(GeanyDocument *doc, gint start, gint len)
-{
-	g_return_if_fail(doc != NULL);
-
-	if (len > 0)
-	{
-		p_sci->indicator_clear(doc->editor->sci, start, start + len);
-	}
-}
-
-
 static void clear_indicators_on_line(GeanyDocument *doc, gint line_number)
 {
 	gint start_pos, length;
@@ -131,7 +121,7 @@
 	start_pos = p_sci->get_position_from_line(doc->editor->sci, line_number);
 	length = p_sci->get_line_length(doc->editor->sci, line_number);
 
-	clear_indicators_on_range(doc, start_pos, length);
+	p_sci->indicator_clear(doc->editor->sci, start_pos, length);
 }
 
 
@@ -158,29 +148,44 @@
 		p_sci->set_selection_end(clickinfo.doc->editor->sci, endword);
 		p_sci->replace_sel(clickinfo.doc->editor->sci, sugg);
 
-		clear_indicators_on_range(clickinfo.doc, startword, endword - startword);
+		p_sci->indicator_clear(clickinfo.doc->editor->sci, startword, endword - startword);
 	}
 }
 
 
 static void on_menu_addword_item_activate(GtkMenuItem *menuitem, gpointer gdata)
 {
-	gint startword, endword;
+	gint startword, endword, i, doc_len;
+	ScintillaObject *sci;
+	GString *str;
 
 	if (clickinfo.doc == NULL || clickinfo.word == NULL || clickinfo.pos == -1)
 		return;
 
-	/** TODO re-check the whole document */
 	speller_add_word(clickinfo.word);
 
-	startword = p_sci->send_message(
-		clickinfo.doc->editor->sci, SCI_WORDSTARTPOSITION, clickinfo.pos, 0);
-	endword = p_sci->send_message(
-		clickinfo.doc->editor->sci, SCI_WORDENDPOSITION, clickinfo.pos, 0);
-	if (startword != endword)
+	/* Remove all indicators on the added word */
+	sci = clickinfo.doc->editor->sci;
+	str = g_string_sized_new(256);
+	doc_len = p_sci->get_length(sci);
+	for (i = 0; i < doc_len; i++)
 	{
-		clear_indicators_on_range(clickinfo.doc, startword, endword - startword);
+		startword = p_sci->send_message(sci, SCI_INDICATORSTART, 0, i);
+		if (startword >= 0)
+		{
+			endword = p_sci->send_message(sci, SCI_INDICATOREND, 0, startword);
+
+			if (str->len < (guint)(endword - startword + 1))
+				str = g_string_set_size(str, endword - startword + 1);
+			p_sci->get_text_range(sci, startword, endword, str->str);
+
+			if (strncmp(str->str, clickinfo.word, str->len) == 0)
+				p_sci->indicator_clear(sci, startword, endword - startword);
+
+			i = endword + 1;
+		}
 	}
+	g_string_free(str, TRUE);
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list