[gedit/wip/spell-checking] auto-spell: more robust code to get word extends at click position
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/spell-checking] auto-spell: more robust code to get word extends at click position
- Date: Mon, 20 Jul 2015 10:11:21 +0000 (UTC)
commit e4f248c53dbaba9014607c792dfe534d9418a917
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 20 12:07:45 2015 +0200
auto-spell: more robust code to get word extends at click position
First do a check that the click position is inside a word.
plugins/spell/gedit-automatic-spell-checker.c | 47 ++++++++++++++++++-------
1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/plugins/spell/gedit-automatic-spell-checker.c b/plugins/spell/gedit-automatic-spell-checker.c
index 08af6b1..e896d31 100644
--- a/plugins/spell/gedit-automatic-spell-checker.c
+++ b/plugins/spell/gedit-automatic-spell-checker.c
@@ -254,25 +254,34 @@ mark_set_cb (GtkTextBuffer *buffer,
}
}
-static void
-get_word_extents_from_mark (GtkTextBuffer *buffer,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkTextMark *mark)
+static gboolean
+get_word_extents_at_click_position (GeditAutomaticSpellChecker *spell,
+ GtkTextIter *start,
+ GtkTextIter *end)
{
- gtk_text_buffer_get_iter_at_mark (buffer, start, mark);
+ GtkTextIter iter;
+ gtk_text_buffer_get_iter_at_mark (spell->buffer, &iter, spell->mark_click);
+
+ if (!gtk_text_iter_inside_word (&iter) &&
+ !gtk_text_iter_ends_word (&iter))
+ {
+ return FALSE;
+ }
+
+ *start = iter;
if (!gtk_text_iter_starts_word (start))
{
gtk_text_iter_backward_word_start (start);
}
- *end = *start;
-
- if (gtk_text_iter_inside_word (end))
+ *end = iter;
+ if (!gtk_text_iter_ends_word (end))
{
gtk_text_iter_forward_word_end (end);
}
+
+ return TRUE;
}
static void
@@ -323,7 +332,10 @@ add_to_dictionary_cb (GtkWidget *menu_item,
GtkTextIter end;
gchar *word;
- get_word_extents_from_mark (spell->buffer, &start, &end, spell->mark_click);
+ if (!get_word_extents_at_click_position (spell, &start, &end))
+ {
+ return;
+ }
word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
@@ -340,7 +352,10 @@ ignore_all_cb (GtkWidget *menu_item,
GtkTextIter end;
gchar *word;
- get_word_extents_from_mark (spell->buffer, &start, &end, spell->mark_click);
+ if (!get_word_extents_at_click_position (spell, &start, &end))
+ {
+ return;
+ }
word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
@@ -358,7 +373,10 @@ replace_word_cb (GtkWidget *menu_item,
gchar *old_word;
const gchar *new_word;
- get_word_extents_from_mark (spell->buffer, &start, &end, spell->mark_click);
+ if (!get_word_extents_at_click_position (spell, &start, &end))
+ {
+ return;
+ }
old_word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
@@ -487,7 +505,10 @@ populate_popup_cb (GtkTextView *view,
GtkTextIter end;
gchar *word;
- get_word_extents_from_mark (spell->buffer, &start, &end, spell->mark_click);
+ if (!get_word_extents_at_click_position (spell, &start, &end))
+ {
+ return;
+ }
if (!gtk_text_iter_has_tag (&start, spell->tag_highlight))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]