Commit 4a89841f authored by Sébastien Wilmet's avatar Sébastien Wilmet

Fix escape bug with the search and replace completion

The completion contents was unescaped before inserting it, and escaped
after retrieving it. But the unescape/escape functions are not
reciprocal. So it's easier to always deal with the original text.

As a consequence, the gedit_history_entry_set_escape_func() function is
no longer needed.

Little problem: there will be bugs with old completion entries, when
upgrading the gedit version.
parent 3da75b4d
......@@ -528,55 +528,4 @@ gedit_history_entry_get_entry (GeditHistoryEntry *entry)
return gtk_bin_get_child (GTK_BIN (entry));
}
static void
escape_cell_data_func (GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
GeditHistoryEntryEscapeFunc escape_func)
{
gchar *str;
gchar *escaped;
gtk_tree_model_get (model, iter, 0, &str, -1);
escaped = escape_func (str);
g_object_set (renderer, "text", escaped, NULL);
g_free (str);
g_free (escaped);
}
void
gedit_history_entry_set_escape_func (GeditHistoryEntry *entry,
GeditHistoryEntryEscapeFunc escape_func)
{
GList *cells;
g_return_if_fail (GEDIT_IS_HISTORY_ENTRY (entry));
cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry));
/* We only have one cell renderer */
g_return_if_fail (cells->data != NULL && cells->next == NULL);
if (escape_func != NULL)
{
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry),
GTK_CELL_RENDERER (cells->data),
(GtkCellLayoutDataFunc) escape_cell_data_func,
escape_func,
NULL);
}
else
{
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry),
GTK_CELL_RENDERER (cells->data),
NULL,
NULL,
NULL);
}
g_list_free (cells);
}
/* ex:set ts=8 noet: */
......@@ -85,10 +85,6 @@ gboolean gedit_history_entry_get_enable_completion
GtkWidget *gedit_history_entry_get_entry (GeditHistoryEntry *entry);
typedef gchar * (* GeditHistoryEntryEscapeFunc) (const gchar *str);
void gedit_history_entry_set_escape_func (GeditHistoryEntry *entry,
GeditHistoryEntryEscapeFunc escape_func);
G_END_DECLS
#endif /* __GEDIT_HISTORY_ENTRY_H__ */
......
......@@ -90,28 +90,18 @@ gedit_replace_dialog_response (GtkDialog *dialog,
str = gtk_entry_get_text (GTK_ENTRY (dlg->priv->replace_text_entry));
if (*str != '\0')
{
gchar *text;
text = gtk_source_utils_unescape_search_text (str);
gedit_history_entry_prepend_text
(GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry),
text);
g_free (text);
str);
}
/* fall through, so that we also save the find entry */
case GEDIT_REPLACE_DIALOG_FIND_RESPONSE:
str = gtk_entry_get_text (GTK_ENTRY (dlg->priv->search_text_entry));
if (*str != '\0')
{
gchar *text;
text = gtk_source_utils_unescape_search_text (str);
gedit_history_entry_prepend_text
(GEDIT_HISTORY_ENTRY (dlg->priv->search_entry),
text);
g_free (text);
str);
}
}
}
......@@ -202,8 +192,6 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
dlg->priv->search_entry = gedit_history_entry_new ("search-for-entry", TRUE);
gtk_widget_set_size_request (dlg->priv->search_entry, 300, -1);
gedit_history_entry_set_escape_func (GEDIT_HISTORY_ENTRY (dlg->priv->search_entry),
(GeditHistoryEntryEscapeFunc) gtk_source_utils_escape_search_text);
gtk_widget_set_hexpand (GTK_WIDGET (dlg->priv->search_entry), TRUE);
dlg->priv->search_text_entry = gedit_history_entry_get_entry (GEDIT_HISTORY_ENTRY (dlg->priv->search_entry));
gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->search_text_entry), TRUE);
......@@ -213,8 +201,6 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
GTK_POS_RIGHT, 1, 1);
dlg->priv->replace_entry = gedit_history_entry_new ("replace-with-entry", TRUE);
gedit_history_entry_set_escape_func (GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry),
(GeditHistoryEntryEscapeFunc) gtk_source_utils_escape_search_text);
gtk_widget_set_hexpand (GTK_WIDGET (dlg->priv->replace_entry), TRUE);
dlg->priv->replace_text_entry = gedit_history_entry_get_entry (GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry));
gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->replace_text_entry), TRUE);
......
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