[gtkhtml] Bug #606167 - Crash on composer Link editing
- From: Milan Crha <mcrha src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtkhtml] Bug #606167 - Crash on composer Link editing
- Date: Thu, 14 Jan 2010 13:15:56 +0000 (UTC)
commit c4e1fd028074d879059b523cbfe4b434b054f097
Author: Milan Crha <mcrha redhat com>
Date: Thu Jan 14 14:14:22 2010 +0100
Bug #606167 - Crash on composer Link editing
components/editor/gtkhtml-editor-signals.c | 54 +++++++++++++++++++++++++---
gtkhtml/htmlengine-edit-cut-and-paste.c | 2 +-
gtkhtml/htmltext.c | 2 +-
3 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/components/editor/gtkhtml-editor-signals.c b/components/editor/gtkhtml-editor-signals.c
index 4e59334..1d35750 100644
--- a/components/editor/gtkhtml-editor-signals.c
+++ b/components/editor/gtkhtml-editor-signals.c
@@ -1014,6 +1014,42 @@ gtkhtml_editor_image_properties_url_entry_changed_cb (GtkWidget *window))
* Link Properties Window
*****************************************************************************/
+static gchar *
+sanitize_description_text (const gchar *ptext)
+{
+ gchar *p, *text = g_strdup (ptext);
+
+ if (!text)
+ return text;
+
+ /* replace line breakers with spaces */
+ for (p = text; *p; p++) {
+ if (*p == '\r' || *p == '\n')
+ *p = ' ';
+ }
+
+ return g_strstrip (text);
+}
+
+static void
+update_link_offsets (GtkhtmlEditor *editor)
+{
+ Link *link;
+ GtkHTML *html;
+
+ g_return_if_fail (editor != NULL);
+ g_return_if_fail (GTKHTML_IS_EDITOR (editor));
+ g_return_if_fail (editor->priv != NULL);
+
+ html = gtkhtml_editor_get_html (editor);
+
+ link = html_text_get_link_at_offset (HTML_TEXT (html->engine->cursor->object), html->engine->cursor->offset);
+ g_return_if_fail (link != NULL);
+
+ editor->priv->link_start_offset = link->start_offset;
+ editor->priv->link_end_offset = link->end_offset;
+}
+
AUTOCONNECTED_SIGNAL_HANDLER (void
gtkhtml_editor_link_properties_description_changed_cb (GtkWidget *window))
{
@@ -1029,8 +1065,7 @@ gtkhtml_editor_link_properties_description_changed_cb (GtkWidget *window))
dsc_entry = WIDGET (LINK_PROPERTIES_DESCRIPTION_ENTRY);
url_entry = WIDGET (LINK_PROPERTIES_URL_ENTRY);
- text = g_strstrip (g_strdup (
- gtk_entry_get_text (GTK_ENTRY (dsc_entry))));
+ text = sanitize_description_text (gtk_entry_get_text (GTK_ENTRY (dsc_entry)));
editor->priv->link_custom_description = (*text != '\0');
@@ -1059,7 +1094,7 @@ gtkhtml_editor_link_properties_description_changed_cb (GtkWidget *window))
gtk_entry_get_text (GTK_ENTRY (url_entry)));
editor->priv->link_object = html->engine->cursor->object;
- editor->priv->link_end_offset = start_offset + length;
+ update_link_offsets (editor);
}
g_free (text);
@@ -1090,7 +1125,9 @@ gtkhtml_editor_link_properties_url_changed_cb (GtkWidget *window))
if (html_engine_is_selection_active (html->engine)) {
html_engine_set_link (html->engine, text);
} else if (!editor->priv->link_custom_description) {
- gtk_entry_set_text (GTK_ENTRY (dsc_entry), text);
+ gchar *descr = sanitize_description_text (text);
+ gtk_entry_set_text (GTK_ENTRY (dsc_entry), descr);
+ g_free (descr);
editor->priv->link_custom_description = FALSE;
} else {
gint start_offset;
@@ -1117,7 +1154,7 @@ gtkhtml_editor_link_properties_url_changed_cb (GtkWidget *window))
html->engine, descr, length, text);
editor->priv->link_object = html->engine->cursor->object;
- editor->priv->link_end_offset = start_offset + length;
+ update_link_offsets (editor);
}
g_free (text);
@@ -1191,6 +1228,13 @@ gtkhtml_editor_link_properties_show_window_cb (GtkWidget *window))
GTK_ENTRY (url_entry),
(url != NULL) ? url : "http://");
+ if (dsc) {
+ gchar *tmp = dsc;
+
+ dsc = sanitize_description_text (dsc);
+ g_free (tmp);
+ }
+
gtk_entry_set_text (GTK_ENTRY (dsc_entry), dsc ? dsc : "");
gtk_widget_grab_focus (url_entry);
diff --git a/gtkhtml/htmlengine-edit-cut-and-paste.c b/gtkhtml/htmlengine-edit-cut-and-paste.c
index c0318e4..25a0ff9 100644
--- a/gtkhtml/htmlengine-edit-cut-and-paste.c
+++ b/gtkhtml/htmlengine-edit-cut-and-paste.c
@@ -1490,7 +1490,7 @@ html_engine_paste_link (HTMLEngine *e, const gchar *text, gint len, const gchar
}
html_engine_paste_text (e, text, len);
- html_text_add_link (HTML_TEXT (e->cursor->object), e, url, target, e->cursor->offset - len, e->cursor->offset);
+ html_text_add_link (HTML_TEXT (e->cursor->object), e, url, target, e->cursor->offset >= len ? e->cursor->offset - len : 0, e->cursor->offset);
g_free (url);
}
diff --git a/gtkhtml/htmltext.c b/gtkhtml/htmltext.c
index 2be78d5..584db26 100644
--- a/gtkhtml/htmltext.c
+++ b/gtkhtml/htmltext.c
@@ -3111,7 +3111,7 @@ html_text_get_text (HTMLText *text, guint offset)
{
gchar *s = text->text;
- while (offset--)
+ while (offset-- && s && *s)
s = g_utf8_next_char (s);
return s;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]