[gtksourceview/gtksourcecompletion] Use provider start iter in default proposal activation
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourcecompletion] Use provider start iter in default proposal activation
- Date: Sun, 27 Sep 2009 10:47:28 +0000 (UTC)
commit 029f094ff510c6783b225de4ace1a59f0e92fd5c
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sun Sep 27 12:46:45 2009 +0200
Use provider start iter in default proposal activation
Default proposal activation will now check
gtk_source_completion_provider_get_start_iter to get the starting iter for
replacing text in the buffer with the proposal text. If a provider does not
implement 'get_start_iter', we default to replacing the current word
(as defined by pango word boundaries).
gtksourceview/gtksourcecompletion.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 2f5b73b..ab42237 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -221,6 +221,8 @@ activate_current_proposal (GtkSourceCompletion *completion)
GtkSourceCompletionProvider *provider = NULL;
GtkTextBuffer *buffer;
const gchar *text;
+ gboolean has_start;
+ GtkTextIter start;
if (!get_selected_proposal (completion, &iter, &provider, &proposal))
{
@@ -231,6 +233,10 @@ activate_current_proposal (GtkSourceCompletion *completion)
gtk_source_completion_hide (completion);
return TRUE;
}
+
+ has_start = gtk_source_completion_provider_get_start_iter (provider,
+ proposal,
+ &start);
/* First hide the completion because the activation might actually
activate another one, which we don't want to hide */
@@ -254,9 +260,21 @@ activate_current_proposal (GtkSourceCompletion *completion)
if (!activated)
{
text = gtk_source_completion_proposal_get_text (proposal);
- gtk_source_completion_utils_replace_current_word (GTK_SOURCE_BUFFER (buffer),
- text ? text : NULL,
- -1);
+
+ if (has_start)
+ {
+ /* Replace from 'start' to 'titer' */
+ gtk_text_buffer_begin_user_action (buffer);
+ gtk_text_buffer_delete (buffer, &start, &titer);
+ gtk_text_buffer_insert (buffer, &start, text, -1);
+ gtk_text_buffer_end_user_action (buffer);
+ }
+ else
+ {
+ gtk_source_completion_utils_replace_current_word (GTK_SOURCE_BUFFER (buffer),
+ text,
+ -1);
+ }
}
g_signal_handler_unblock (buffer,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]