[gspell/wip/entry-context-menu: 1/3] EntryUtils: get list of words without preedit string



commit 50b77c8e89f63eff96826b4e6592794da416f88e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Nov 25 20:52:20 2016 +0100

    EntryUtils: get list of words without preedit string
    
    Don't take into account the preedit string for spell checking.  It is
    anyway planned to *not* spell check the word being typed (so the word at
    the cursor, with the preedit string). So it actually doesn't change the
    outside result if we take into account the preedit string or not.

 gspell/gspell-entry-utils.c |   42 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/gspell/gspell-entry-utils.c b/gspell/gspell-entry-utils.c
index fa53b79..5ab8342 100644
--- a/gspell/gspell-entry-utils.c
+++ b/gspell/gspell-entry-utils.c
@@ -38,27 +38,56 @@ _gspell_entry_word_free (gpointer data)
        }
 }
 
-/* Returns: (transfer full) (element-type GspellEntryWord): free with
+/* Without the preedit string.
+ * Free @log_attrs with g_free().
+ */
+static void
+get_pango_log_attrs (GtkEntry      *entry,
+                    PangoLogAttr **log_attrs,
+                    gint          *n_attrs)
+{
+       GtkEntryBuffer *buffer;
+
+       g_assert (log_attrs != NULL);
+       g_assert (n_attrs != NULL);
+
+       buffer = gtk_entry_get_buffer (entry);
+
+       *n_attrs = gtk_entry_buffer_get_length (buffer) + 1;
+       *log_attrs = g_new0 (PangoLogAttr, *n_attrs);
+
+       pango_get_log_attrs (gtk_entry_buffer_get_text (buffer),
+                            gtk_entry_buffer_get_bytes (buffer),
+                            -1,
+                            NULL,
+                            *log_attrs,
+                            *n_attrs);
+}
+
+/* Returns: (transfer full) (element-type GspellEntryWord): the list of words in
+ * @entry, without the preedit string. Free with
  * g_slist_free_full (words, _gspell_entry_word_free);
+ *
+ * The preedit string is not included, because the current word being typed
+ * should not be marked as misspelled, so it doesn't change whether the preedit
+ * string is included or not, and the code is simpler without.
  */
 GSList *
 _gspell_entry_utils_get_words (GtkEntry *entry)
 {
-       PangoLayout *layout;
        const gchar *text;
        const gchar *cur_text_pos;
        const gchar *word_start;
        gint word_start_char_pos;
-       const PangoLogAttr *attrs;
-       gint n_attrs = 0;
+       PangoLogAttr *attrs;
+       gint n_attrs;
        gint attr_num;
        GSList *list = NULL;
 
        g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
 
-       layout = gtk_entry_get_layout (entry);
        text = gtk_entry_get_text (entry);
-       attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+       get_pango_log_attrs (entry, &attrs, &n_attrs);
 
        attr_num = 0;
        cur_text_pos = text;
@@ -116,6 +145,7 @@ _gspell_entry_utils_get_words (GtkEntry *entry)
                cur_text_pos = g_utf8_find_next_char (cur_text_pos, NULL);
        }
 
+       g_free (attrs);
        return g_slist_reverse (list);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]