[gtksourceview/wip/completion-fix] Completion: make the code more robust wrt contexts
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/completion-fix] Completion: make the code more robust wrt contexts
- Date: Sat, 11 Oct 2014 13:58:24 +0000 (UTC)
commit 9fe756c699c85779868a9377b01a8546ba720a46
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Oct 11 15:53:07 2014 +0200
Completion: make the code more robust wrt contexts
Before calling a CompletionProvider function, be sure the context is
still valid. A CompletionProvider should also make the verification, but
since the verification was not possible before, old code can crash
without this commit.
gtksourceview/gtksourcecompletion.c | 35 ++++++++++++++++++++++++++++++-----
1 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 8f1e435..40b1619 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -321,9 +321,15 @@ static GList *
select_providers (GList *providers,
GtkSourceCompletionContext *context)
{
+ GtkTextIter context_iter;
GList *selection = NULL;
GList *l;
+ if (!gtk_source_completion_context_get_iter (context, &context_iter))
+ {
+ return NULL;
+ }
+
for (l = providers; l != NULL; l = l->next)
{
GtkSourceCompletionProvider *provider = l->data;
@@ -473,7 +479,14 @@ update_window_position (GtkSourceCompletion *completion)
if (get_selected_proposal (completion, &provider, &proposal))
{
- if (gtk_source_completion_provider_get_start_iter (provider,
+ GtkTextIter context_iter;
+ gboolean valid_context;
+
+ valid_context = gtk_source_completion_context_get_iter (completion->priv->context,
+ &context_iter);
+
+ if (valid_context &&
+ gtk_source_completion_provider_get_start_iter (provider,
completion->priv->context,
proposal,
&iter))
@@ -666,6 +679,8 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
GtkSourceCompletionProvider *provider = NULL;
GtkSourceCompletionProposal *proposal = NULL;
GtkTextIter insert_iter;
+ GtkTextIter context_iter;
+ gboolean valid_context;
gboolean activated;
if (completion->priv->view == NULL)
@@ -684,7 +699,10 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
activated = gtk_source_completion_provider_activate_proposal (provider, proposal, &insert_iter);
- if (!activated)
+ valid_context = gtk_source_completion_context_get_iter (completion->priv->context,
+ &context_iter);
+
+ if (!activated && valid_context)
{
GtkTextIter start_iter;
gchar *text = gtk_source_completion_proposal_get_text (proposal);
@@ -1356,6 +1374,8 @@ update_completion (GtkSourceCompletion *completion,
GtkSourceCompletionContext *context)
{
GList *item;
+ GtkTextIter context_iter;
+ gboolean valid_context;
/* Copy the parameters, because they can be freed by reset_completion(). */
GList *providers_copy = g_list_copy (providers);
@@ -1374,10 +1394,15 @@ update_completion (GtkSourceCompletion *completion,
replace_model (completion);
- for (item = providers_copy; item != NULL; item = g_list_next (item))
+ valid_context = gtk_source_completion_context_get_iter (context_copy, &context_iter);
+
+ if (valid_context)
{
- GtkSourceCompletionProvider *provider = item->data;
- gtk_source_completion_provider_populate (provider, context_copy);
+ for (item = providers_copy; item != NULL; item = g_list_next (item))
+ {
+ GtkSourceCompletionProvider *provider = item->data;
+ gtk_source_completion_provider_populate (provider, context_copy);
+ }
}
g_list_free (providers_copy);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]