Commit 4718ab52 authored by Christian Hergert's avatar Christian Hergert
Browse files

completion: add helper to remove common prefix

Not exactly the best implementation, but seems to do the job.

Related #1416
parent 34ebb161
......@@ -1790,3 +1790,73 @@ ide_completion_fuzzy_highlight (const gchar *haystack,
return g_string_free (ret, FALSE);
}
static gboolean
find_suffix_match (const GtkTextIter *limit,
const GtkTextIter *end,
GtkTextIter *found_start,
GtkTextIter *found_end,
const char *prefix,
gsize n_chars)
{
g_autofree gchar *copy = g_malloc (n_chars * 4 + 1);
GtkTextIter mb, me;
g_utf8_strncpy (copy, prefix, n_chars);
g_print ("%s\n", prefix);
if (gtk_text_iter_backward_search (end, copy, GTK_TEXT_SEARCH_TEXT_ONLY, &mb, &me, limit))
{
if (gtk_text_iter_equal (&me, end))
{
*found_start = mb;
*found_end = me;
return TRUE;
}
g_print ("Blah\n");
}
return FALSE;
}
void
ide_completion_remove_common_prefix (IdeCompletion *self,
GtkTextIter *begin,
const gchar *prefix)
{
GtkTextIter rm_begin;
GtkTextIter rm_end;
GtkTextIter line_start;
GtkTextIter found_start, found_end;
gboolean found = FALSE;
gsize len;
gsize count = 1;
g_return_if_fail (IDE_IS_COMPLETION (self));
g_return_if_fail (self->context != NULL);
g_return_if_fail (begin != NULL);
if (prefix == NULL || prefix[0] == 0)
return;
len = g_utf8_strlen (prefix, -1);
line_start = *begin;
gtk_text_iter_set_line_offset (&line_start, 0);
while (count <= len &&
find_suffix_match (&line_start, begin, &found_start, &found_end, prefix, count))
{
rm_begin = found_start;
rm_end = found_end;
count++;
found = TRUE;
}
if (found)
{
gtk_text_buffer_delete (gtk_text_iter_get_buffer (begin), &rm_begin, &rm_end);
*begin = rm_begin;
}
}
......@@ -38,44 +38,48 @@ IDE_AVAILABLE_IN_3_32
G_DECLARE_FINAL_TYPE (IdeCompletion, ide_completion, IDE, COMPLETION, GObject)
IDE_AVAILABLE_IN_3_32
IdeCompletionDisplay *ide_completion_get_display (IdeCompletion *self);
IdeCompletionDisplay *ide_completion_get_display (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
GtkSourceView *ide_completion_get_view (IdeCompletion *self);
GtkSourceView *ide_completion_get_view (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
GtkTextBuffer *ide_completion_get_buffer (IdeCompletion *self);
GtkTextBuffer *ide_completion_get_buffer (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_block_interactive (IdeCompletion *self);
void ide_completion_block_interactive (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_unblock_interactive (IdeCompletion *self);
void ide_completion_unblock_interactive (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_add_provider (IdeCompletion *self,
IdeCompletionProvider *provider);
void ide_completion_add_provider (IdeCompletion *self,
IdeCompletionProvider *provider);
IDE_AVAILABLE_IN_3_32
void ide_completion_remove_provider (IdeCompletion *self,
IdeCompletionProvider *provider);
void ide_completion_remove_provider (IdeCompletion *self,
IdeCompletionProvider *provider);
IDE_AVAILABLE_IN_3_32
guint ide_completion_get_n_rows (IdeCompletion *self);
guint ide_completion_get_n_rows (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_set_n_rows (IdeCompletion *self,
guint n_rows);
void ide_completion_set_n_rows (IdeCompletion *self,
guint n_rows);
IDE_AVAILABLE_IN_3_32
void ide_completion_hide (IdeCompletion *self);
void ide_completion_hide (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_show (IdeCompletion *self);
void ide_completion_show (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_cancel (IdeCompletion *self);
void ide_completion_cancel (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
gboolean ide_completion_is_visible (IdeCompletion *self);
gboolean ide_completion_is_visible (IdeCompletion *self);
IDE_AVAILABLE_IN_3_32
void ide_completion_move_cursor (IdeCompletion *self,
GtkMovementStep step,
gint direction);
void ide_completion_move_cursor (IdeCompletion *self,
GtkMovementStep step,
gint direction);
IDE_AVAILABLE_IN_3_32
gboolean ide_completion_fuzzy_match (const gchar *haystack,
const gchar *casefold_needle,
guint *priority);
gboolean ide_completion_fuzzy_match (const gchar *haystack,
const gchar *casefold_needle,
guint *priority);
IDE_AVAILABLE_IN_3_32
gchar *ide_completion_fuzzy_highlight (const gchar *haystack,
const gchar *casefold_query);
gchar *ide_completion_fuzzy_highlight (const gchar *haystack,
const gchar *casefold_query);
IDE_AVAILABLE_IN_3_40
void ide_completion_remove_common_prefix (IdeCompletion *self,
GtkTextIter *begin,
const gchar *prefix);
G_END_DECLS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment