[evolution/wip/webkit2] Bug 750299 - [regression] Hyperlinks create duplicate text, then deleting the duplicate makes the hy
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Bug 750299 - [regression] Hyperlinks create duplicate text, then deleting the duplicate makes the hy
- Date: Tue, 19 Jul 2016 14:17:23 +0000 (UTC)
commit 82a73f5090b366ac8b4c6aca582a03f6a5378327
Author: Tomas Popela <tpopela redhat com>
Date: Tue Jul 19 15:35:21 2016 +0200
Bug 750299 - [regression] Hyperlinks create duplicate text, then deleting the duplicate makes the
hyperlink blow up to the whole line
Fix the EHTMLEditorLinkDialog as between showing the dialog and clicking the "OK"
button the selection in composer was lost that later lead to creating the duplicate
text. Also save the link under the cursor straight in the EHTMLEditor and then pass
it to the dialog to avoid looking for it on various places again.
Also it showed up that I completely forgot about this dialog when implementing the
undo/redo in the composer, so previously doing so after working with dialog would
lead to undefined behavior.
Replace the webkit_dom_html_anchor_element_get_href with webkit_dom_element_get_attribute
as the first one would return just "http:/" when we would previously set the "http://"
as a value of the href attribute.
e-util/e-content-editor.c | 28 +++
e-util/e-content-editor.h | 10 +
e-util/e-html-editor-actions.h | 2 +
e-util/e-html-editor-link-dialog.c | 29 ++-
e-util/e-html-editor.c | 2 +
modules/webkit-editor/e-webkit-editor.c | 26 ++-
.../web-extension/e-dialogs-dom-functions.c | 243 ++++++++++++++------
.../web-extension/e-dialogs-dom-functions.h | 8 +-
.../web-extension/e-editor-dom-functions.c | 2 -
.../web-extension/e-editor-web-extension.c | 43 +++-
10 files changed, 306 insertions(+), 87 deletions(-)
---
diff --git a/e-util/e-content-editor.c b/e-util/e-content-editor.c
index 580c783..2224af0 100644
--- a/e-util/e-content-editor.c
+++ b/e-util/e-content-editor.c
@@ -2562,6 +2562,34 @@ e_content_editor_image_set_height_follow (EContentEditor *editor,
}
void
+e_content_editor_on_link_dialog_open (EContentEditor *editor)
+{
+ EContentEditorInterface *iface;
+
+ g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+
+ iface = E_CONTENT_EDITOR_GET_IFACE (editor);
+ g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface->on_link_dialog_open != NULL);
+
+ iface->on_link_dialog_open (editor);
+}
+
+void
+e_content_editor_on_link_dialog_close (EContentEditor *editor)
+{
+ EContentEditorInterface *iface;
+
+ g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+
+ iface = E_CONTENT_EDITOR_GET_IFACE (editor);
+ g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface->on_link_dialog_close != NULL);
+
+ iface->on_link_dialog_close (editor);
+}
+
+void
e_content_editor_link_get_values (EContentEditor *editor,
gchar **href,
gchar **text)
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index e2c3256..8d3d64e 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -245,6 +245,10 @@ struct _EContentEditorInterface {
gchar * (*image_get_align) (EContentEditor *editor);
+ void (*on_link_dialog_open) (EContentEditor *editor);
+
+ void (*on_link_dialog_close) (EContentEditor *editor);
+
void (*link_get_values) (EContentEditor *editor,
gchar **href,
gchar **text);
@@ -757,6 +761,12 @@ void e_content_editor_image_set_height_follow
(EContentEditor *editor,
gboolean value);
+void e_content_editor_on_link_dialog_open
+ (EContentEditor *editor);
+
+void e_content_editor_on_link_dialog_close
+ (EContentEditor *editor);
+
void e_content_editor_link_get_values
(EContentEditor *editor,
gchar **href,
diff --git a/e-util/e-html-editor-actions.h b/e-util/e-html-editor-actions.h
index 5211cce..232d63e 100644
--- a/e-util/e-html-editor-actions.h
+++ b/e-util/e-html-editor-actions.h
@@ -41,6 +41,8 @@
E_HTML_EDITOR_ACTION ((editor), "context-insert-column-after")
#define E_HTML_EDITOR_ACTION_CONTEXT_INSERT_COLUMN_BEFORE(editor) \
E_HTML_EDITOR_ACTION ((editor), "context-insert-column-before")
+#define E_HTML_EDITOR_ACTION_CONTEXT_INSERT_LINK(editor) \
+ E_HTML_EDITOR_ACTION ((editor), "context-insert-link")
#define E_HTML_EDITOR_ACTION_CONTEXT_INSERT_ROW_ABOVE(editor) \
E_HTML_EDITOR_ACTION ((editor), "context-insert-row-above")
#define E_HTML_EDITOR_ACTION_CONTEXT_INSERT_ROW_BELOW(editor) \
diff --git a/e-util/e-html-editor-link-dialog.c b/e-util/e-html-editor-link-dialog.c
index 9d788e1..5db93ed 100644
--- a/e-util/e-html-editor-link-dialog.c
+++ b/e-util/e-html-editor-link-dialog.c
@@ -91,6 +91,8 @@ html_editor_link_dialog_remove_link (EHTMLEditorLinkDialog *dialog)
cnt_editor = e_html_editor_get_content_editor (editor);
e_content_editor_selection_unlink (cnt_editor);
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
}
static void
@@ -114,7 +116,7 @@ static gboolean
html_editor_link_dialog_entry_key_pressed (EHTMLEditorLinkDialog *dialog,
GdkEventKey *event)
{
- /* We can't do thins in key_released, because then you could not open
+ /* We can't do things in key_released, because then you could not open
* this dialog from main menu by pressing enter on Insert->Link action */
if (event->keyval == GDK_KEY_Return) {
html_editor_link_dialog_ok (dialog);
@@ -125,6 +127,23 @@ html_editor_link_dialog_entry_key_pressed (EHTMLEditorLinkDialog *dialog,
}
static void
+html_editor_link_dialog_hide (GtkWidget *widget)
+{
+ EHTMLEditor *editor;
+ EHTMLEditorLinkDialog *dialog;
+ EContentEditor *cnt_editor;
+
+ dialog = E_HTML_EDITOR_LINK_DIALOG (widget);
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ cnt_editor = e_html_editor_get_content_editor (editor);
+
+ e_content_editor_on_link_dialog_close (cnt_editor);
+
+ /* Chain up to parent implementation */
+ GTK_WIDGET_CLASS (e_html_editor_link_dialog_parent_class)->hide (widget);
+}
+
+static void
html_editor_link_dialog_show (GtkWidget *widget)
{
EHTMLEditor *editor;
@@ -144,19 +163,22 @@ html_editor_link_dialog_show (GtkWidget *widget)
dialog->priv->label_autofill = TRUE;
+ e_content_editor_on_link_dialog_open (cnt_editor);
+
e_content_editor_link_get_values (cnt_editor, &href, &text);
if (href && *href)
gtk_entry_set_text (
GTK_ENTRY (dialog->priv->url_edit), href);
- else {
+ else
gtk_widget_set_sensitive (
dialog->priv->remove_link_button, FALSE);
- }
+
g_free (href);
if (text && *text) {
gtk_entry_set_text (
GTK_ENTRY (dialog->priv->label_edit), text);
+ dialog->priv->label_autofill = FALSE;
}
g_free (text);
@@ -173,6 +195,7 @@ e_html_editor_link_dialog_class_init (EHTMLEditorLinkDialogClass *class)
widget_class = GTK_WIDGET_CLASS (class);
widget_class->show = html_editor_link_dialog_show;
+ widget_class->hide = html_editor_link_dialog_hide;
}
static void
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index a9582fd..73a6eb3 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -344,6 +344,8 @@ html_editor_update_actions (EHTMLEditor *editor)
gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_IMAGE), visible);
visible = (flags & E_CONTENT_EDITOR_NODE_IS_ANCHOR);
+ if (visible)
+ gtk_action_set_visible (ACTION (CONTEXT_INSERT_LINK), FALSE);
gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_LINK), visible);
visible = (flags & E_CONTENT_EDITOR_NODE_IS_H_RULE);
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 0004486..1b8b4d7 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -3284,7 +3284,29 @@ webkit_editor_selection_unlink (EContentEditor *editor)
wk_editor = E_WEBKIT_EDITOR (editor);
webkit_editor_call_simple_extension_function (
- wk_editor, "EEditorSelectionUnlink");
+ wk_editor, "EEditorLinkDialogUnlink");
+}
+
+static void
+webkit_editor_on_link_dialog_open (EContentEditor *editor)
+{
+ EWebKitEditor *wk_editor;
+
+ wk_editor = E_WEBKIT_EDITOR (editor);
+
+ webkit_editor_call_simple_extension_function (
+ wk_editor, "EEditorLinkDialogOpen");
+}
+
+static void
+webkit_editor_on_link_dialog_close (EContentEditor *editor)
+{
+ EWebKitEditor *wk_editor;
+
+ wk_editor = E_WEBKIT_EDITOR (editor);
+
+ webkit_editor_call_simple_extension_function (
+ wk_editor, "EEditorLinkDialogClose");
}
static void
@@ -6111,6 +6133,8 @@ e_webkit_editor_content_editor_init (EContentEditorInterface *iface)
iface->image_set_width_follow = webkit_editor_image_set_width_follow;
iface->image_get_width = webkit_editor_image_get_width;
iface->image_get_height = webkit_editor_image_get_height;
+ iface->on_link_dialog_open = webkit_editor_on_link_dialog_open;
+ iface->on_link_dialog_close = webkit_editor_on_link_dialog_close;
iface->link_set_values = webkit_editor_link_set_values;
iface->link_get_values = webkit_editor_link_get_values;
iface->page_set_text_color = webkit_editor_page_set_text_color;
diff --git a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
index 8c49a53..0731363 100644
--- a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
@@ -457,18 +457,20 @@ get_current_hrule_element (WebKitDOMDocument *document)
}
gboolean
-e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page,
- WebKitDOMNode *node_under_mouse_click)
+e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page)
{
EEditorUndoRedoManager *manager;
gboolean created = FALSE;
WebKitDOMDocument *document;
WebKitDOMElement *rule;
+ WebKitDOMNode *node_under_mouse_click;
g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), FALSE);
document = e_editor_page_get_document (editor_page);
+ node_under_mouse_click = e_editor_page_get_node_under_mouse_click (editor_page);
+
if (node_under_mouse_click && WEBKIT_DOM_IS_HTML_HR_ELEMENT (node_under_mouse_click)) {
rule = WEBKIT_DOM_ELEMENT (node_under_mouse_click);
webkit_dom_element_set_id (rule, "-x-evo-current-hr");
@@ -555,12 +557,15 @@ get_current_image_element (WebKitDOMDocument *document)
}
void
-e_dialogs_dom_image_mark_image (EEditorPage *editor_page,
- WebKitDOMNode *node_under_mouse_click)
+e_dialogs_dom_image_mark_image (EEditorPage *editor_page)
{
EEditorUndoRedoManager *manager;
+ WebKitDOMNode *node_under_mouse_click;
g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
+
+ node_under_mouse_click = e_editor_page_get_node_under_mouse_click (editor_page);
+
g_return_if_fail (node_under_mouse_click && WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT
(node_under_mouse_click));
webkit_dom_element_set_id (WEBKIT_DOM_ELEMENT (node_under_mouse_click), "-x-evo-current-img");
@@ -673,7 +678,6 @@ e_dialogs_dom_image_get_element_url (EEditorPage *editor_page)
/* ******************** Link Dialog ***************** */
-/* FIXME WK2 apply changes from commit 18c5e81 */
void
e_dialogs_dom_link_commit (EEditorPage *editor_page,
const gchar *url,
@@ -688,13 +692,31 @@ e_dialogs_dom_link_commit (EEditorPage *editor_page,
link = webkit_dom_document_get_element_by_id (document, "-x-evo-current-anchor");
if (link) {
+ WebKitDOMElement *element;
+
webkit_dom_html_anchor_element_set_href (
WEBKIT_DOM_HTML_ANCHOR_ELEMENT (link), url);
webkit_dom_html_element_set_inner_text (
WEBKIT_DOM_HTML_ELEMENT (link), inner_text, NULL);
- webkit_dom_element_remove_attribute (link, "id");
+
+ element = webkit_dom_document_create_element (document, "SPAN", NULL);
+ webkit_dom_element_set_id (element, "-x-evo-selection-end-marker");
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (link)),
+ WEBKIT_DOM_NODE (element),
+ webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (link)),
+ NULL);
+
+ element = webkit_dom_document_create_element (document, "SPAN", NULL);
+ webkit_dom_element_set_id (element, "-x-evo-selection-start-marker");
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (link)),
+ WEBKIT_DOM_NODE (element),
+ webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (link)),
+ NULL);
+
+ e_editor_dom_selection_restore (editor_page);
} else {
- gchar *text;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMRange *range;
@@ -703,93 +725,160 @@ e_dialogs_dom_link_commit (EEditorPage *editor_page,
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
- if (!dom_selection ||
- (webkit_dom_dom_selection_get_range_count (dom_selection) == 0)) {
- g_object_unref (dom_selection);
- return;
- }
-
+ e_editor_dom_selection_restore (editor_page);
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
+ if (webkit_dom_range_get_collapsed (range, NULL)) {
+ WebKitDOMElement *selection_marker;
+ WebKitDOMElement *anchor;
+
+ e_editor_dom_selection_save (editor_page);
+ selection_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ anchor = webkit_dom_document_create_element (document, "A", NULL);
+ webkit_dom_element_set_attribute (anchor, "href", url, NULL);
+ webkit_dom_element_set_id (anchor, "-x-evo-current-anchor");
+ webkit_dom_html_element_set_inner_text (
+ WEBKIT_DOM_HTML_ELEMENT (anchor), inner_text, NULL);
- /* Check whether a text is selected or not */
- text = webkit_dom_range_get_text (range);
- if (text && *text) {
- e_editor_dom_create_link (editor_page, url);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_marker)),
+ WEBKIT_DOM_NODE (anchor),
+ WEBKIT_DOM_NODE (selection_marker),
+ NULL);
+ e_editor_dom_selection_restore (editor_page);
} else {
- gchar *html = g_strdup_printf (
- "<a href=\"%s\">%s</a>", url, inner_text);
+ gchar *text;
- e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_INSERT_HTML, html);
- g_free (html);
- }
+ text = webkit_dom_range_get_text (range);
+ if (text && *text) {
+ EEditorUndoRedoManager *manager;
+ EEditorHistoryEvent *ev;
- g_free (text);
+ e_editor_dom_create_link (editor_page, url);
+
+ manager = e_editor_page_get_undo_redo_manager (editor_page);
+ ev = e_editor_undo_redo_manager_get_current_history_event (manager);
+
+ ev->data.dom.from =
+ WEBKIT_DOM_NODE (webkit_dom_document_create_text_node (document,
text));
+
+ webkit_dom_dom_selection_collapse_to_end (dom_selection, NULL);
+ }
+ g_free (text);
+ }
g_object_unref (range);
g_object_unref (dom_selection);
}
}
-GVariant *
-e_dialogs_dom_link_show (EEditorPage *editor_page)
+void
+e_dialogs_dom_link_close (EEditorPage *editor_page)
{
- GVariant *result = NULL;
WebKitDOMDocument *document;
- WebKitDOMDOMWindow *dom_window;
- WebKitDOMDOMSelection *dom_selection;
- WebKitDOMRange *range;
WebKitDOMElement *link;
- g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), NULL);
+ g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
document = e_editor_page_get_document (editor_page);
- dom_window = webkit_dom_document_get_default_view (document);
- dom_selection = webkit_dom_dom_window_get_selection (dom_window);
- g_object_unref (dom_window);
- /* No selection at all */
- if (!dom_selection ||
- webkit_dom_dom_selection_get_range_count (dom_selection) < 1) {
- result = g_variant_new ("(ss)", "", "");
- return result;
+ link = webkit_dom_document_get_element_by_id (document, "-x-evo-current-anchor");
+ if (link) {
+ EEditorUndoRedoManager *manager;
+ EEditorHistoryEvent *ev;
+
+ manager = e_editor_page_get_undo_redo_manager (editor_page);
+ ev = e_editor_undo_redo_manager_get_current_history_event (manager);
+ if (ev->type == HISTORY_LINK_DIALOG) {
+ ev->data.dom.to = webkit_dom_node_clone_node_with_error (
+ WEBKIT_DOM_NODE (link), TRUE, NULL);
+
+ if (ev->data.dom.from && webkit_dom_node_is_equal_node (ev->data.dom.from,
ev->data.dom.to))
+ e_editor_undo_redo_manager_remove_current_history_event (manager);
+ else
+ e_editor_dom_selection_get_coordinates (
+ editor_page, &ev->after.start.x, &ev->after.start.y,
&ev->after.end.x, &ev->after.end.y);
+ }
+ webkit_dom_element_remove_attribute (link, "id");
}
+}
- range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
- link = dom_node_find_parent_element (
- webkit_dom_range_get_start_container (range, NULL), "A");
- if (!link) {
- if ((webkit_dom_range_get_start_container (range, NULL) !=
- webkit_dom_range_get_end_container (range, NULL)) ||
- (webkit_dom_range_get_start_offset (range, NULL) !=
- webkit_dom_range_get_end_offset (range, NULL))) {
-
- WebKitDOMDocumentFragment *fragment;
- fragment = webkit_dom_range_clone_contents (range, NULL);
- link = dom_node_find_child_element (WEBKIT_DOM_NODE (fragment), "A");
- } else {
- /* get element that was clicked on */
- WebKitDOMNode *node;
-
- node = webkit_dom_range_get_common_ancestor_container (range, NULL);
- if (node && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) {
- link = dom_node_find_parent_element (node, "A");
- if (link && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (link))
- link = NULL;
- } else
- link = WEBKIT_DOM_ELEMENT (node);
+void
+e_dialogs_dom_link_open (EEditorPage *editor_page)
+{
+ EEditorUndoRedoManager *manager;
+ WebKitDOMDocument *document;
+ WebKitDOMElement *link = NULL;
+ WebKitDOMNode *node_under_mouse_click;
+
+ g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
+
+ document = e_editor_page_get_document (editor_page);
+
+ node_under_mouse_click = e_editor_page_get_node_under_mouse_click (editor_page);
+ if (node_under_mouse_click && WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node_under_mouse_click)) {
+ link = WEBKIT_DOM_ELEMENT (node_under_mouse_click);
+ } else {
+ if (!(link = webkit_dom_document_get_element_by_id (document, "-x-evo-current-anchor"))) {
+ if (node_under_mouse_click) {
+ link = dom_node_find_parent_element (node_under_mouse_click, "A");
+ } else {
+ WebKitDOMElement *selection_start;
+
+ e_editor_dom_selection_save (editor_page);
+
+ selection_start = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+
+ link = dom_node_find_parent_element (WEBKIT_DOM_NODE (selection_start), "A");
+
+ e_editor_dom_selection_restore (editor_page);
+ }
}
}
+ if (link)
+ webkit_dom_element_set_id (link, "-x-evo-current-anchor");
+
+ manager = e_editor_page_get_undo_redo_manager (editor_page);
+ if (!e_editor_undo_redo_manager_is_operation_in_progress (manager)) {
+ EEditorHistoryEvent *ev;
+
+ ev = g_new0 (EEditorHistoryEvent, 1);
+ ev->type = HISTORY_LINK_DIALOG;
+
+ e_editor_dom_selection_get_coordinates (
+ editor_page, &ev->before.start.x, &ev->before.start.y, &ev->before.end.x,
&ev->before.end.y);
+ if (link)
+ ev->data.dom.from = webkit_dom_node_clone_node_with_error (
+ WEBKIT_DOM_NODE (link), TRUE, NULL);
+ else
+ ev->data.dom.from = NULL;
+ e_editor_undo_redo_manager_insert_history_event (manager, ev);
+ }
+}
+
+GVariant *
+e_dialogs_dom_link_show (EEditorPage *editor_page)
+{
+ GVariant *result = NULL;
+ WebKitDOMDocument *document;
+ WebKitDOMElement *link;
+
+ g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), NULL);
+
+ document = e_editor_page_get_document (editor_page);
+
+ e_editor_dom_selection_save (editor_page);
+
+ link = webkit_dom_document_get_element_by_id (document, "-x-evo-current-anchor");
if (link) {
gchar *href, *text;
- href = webkit_dom_html_anchor_element_get_href (
- WEBKIT_DOM_HTML_ANCHOR_ELEMENT (link));
+ href = webkit_dom_element_get_attribute (link, "href");
text = webkit_dom_html_element_get_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (link));
-
- webkit_dom_element_set_id (
- WEBKIT_DOM_ELEMENT (link), "-x-evo-current-anchor");
+ WEBKIT_DOM_HTML_ELEMENT (link));
result = g_variant_new ("(ss)", href, text);
@@ -797,16 +886,28 @@ e_dialogs_dom_link_show (EEditorPage *editor_page)
g_free (href);
} else {
gchar *text;
+ WebKitDOMDOMWindow *dom_window;
+ WebKitDOMDOMSelection *dom_selection;
+ WebKitDOMRange *range;
+
+ dom_window = webkit_dom_document_get_default_view (document);
+ dom_selection = webkit_dom_dom_window_get_selection (dom_window);
+ g_object_unref (dom_window);
+
+ /* No selection at all */
+ if (!dom_selection || webkit_dom_dom_selection_get_range_count (dom_selection) < 1)
+ result = g_variant_new ("(ss)", "", "");
+ range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
text = webkit_dom_range_get_text (range);
- if (text && *text)
+ if (text)
result = g_variant_new ("(ss)", "", text);
g_free (text);
- }
- g_object_unref (range);
- g_object_unref (dom_selection);
+ g_object_unref (range);
+ g_object_unref (dom_selection);
+ }
return result;
}
diff --git a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
index ac5f286..5e3ae4c 100644
--- a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
+++ b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
@@ -66,15 +66,13 @@ void e_dialogs_dom_cell_set_element_bg_color
/* ******************** HRule Dialog ***************** */
-gboolean e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page,
- WebKitDOMNode *node_under_mouse_click);
+gboolean e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page);
void e_dialogs_dom_save_history_on_exit
(EEditorPage *editor_page);
/* ******************** Image Dialog ***************** */
-void e_dialogs_dom_image_mark_image (EEditorPage *editor_page,
- WebKitDOMNode *node_under_mouse_click);
+void e_dialogs_dom_image_mark_image (EEditorPage *editor_page);
void e_dialogs_dom_image_save_history_on_exit
(EEditorPage *editor_page);
void e_dialogs_dom_image_set_element_url
@@ -89,6 +87,8 @@ void e_dialogs_dom_link_commit (EEditorPage *editor_page,
const gchar *url,
const gchar *inner_text);
GVariant * e_dialogs_dom_link_show (EEditorPage *editor_page);
+void e_dialogs_dom_link_open (EEditorPage *editor_page);
+void e_dialogs_dom_link_close (EEditorPage *editor_page);
/* ******************** Page Dialog ***************** */
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 770b092..a38314f 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -11350,8 +11350,6 @@ e_editor_dom_selection_unlink (EEditorPage *editor_page)
} else
link = WEBKIT_DOM_ELEMENT (node);
}
- } else {
- e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_UNLINK, NULL);
}
g_object_unref (range);
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 84e8398..6a0e0df 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -385,7 +385,13 @@ static const gchar *introspection_xml =
" <method name='EEditorDialogInsertRowBelow'>"
" <arg type='t' name='page_id' direction='in'/>"
" </method>"
-" <method name='EEditorDialogDOMUnlink'>"
+" <method name='EEditorLinkDialogOpen'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" </method>"
+" <method name='EEditorLinkDialogClose'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" </method>"
+" <method name='EEditorLinkDialogUnlink'>"
" <arg type='t' name='page_id' direction='in'/>"
" </method>"
" <method name='EEditorDialogSaveHistoryForCut'>"
@@ -985,7 +991,7 @@ handle_method_call (GDBusConnection *connection,
if (!editor_page)
goto error;
- created_new_hr = e_dialogs_dom_hrule_find_hrule (editor_page,
e_editor_page_get_node_under_mouse_click (editor_page));
+ created_new_hr = e_dialogs_dom_hrule_find_hrule (editor_page);
g_dbus_method_invocation_return_value (
invocation, g_variant_new ("(b)", created_new_hr));
@@ -1045,7 +1051,7 @@ handle_method_call (GDBusConnection *connection,
if (!editor_page)
goto error;
- e_dialogs_dom_image_mark_image (editor_page, e_editor_page_get_node_under_mouse_click
(editor_page));
+ e_dialogs_dom_image_mark_image (editor_page);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "EEditorImageDialogSaveHistoryOnExit") == 0) {
@@ -1303,8 +1309,7 @@ handle_method_call (GDBusConnection *connection,
goto error;
g_dbus_method_invocation_return_value (
- invocation,
- e_dialogs_dom_link_show (editor_page));
+ invocation, e_dialogs_dom_link_show (editor_page));
} else if (g_strcmp0 (method_name, "EEditorPageDialogSaveHistory") == 0) {
g_variant_get (parameters, "(t)", &page_id);
@@ -1516,13 +1521,39 @@ handle_method_call (GDBusConnection *connection,
e_editor_dom_insert_row_below (editor_page);
g_dbus_method_invocation_return_value (invocation, NULL);
- } else if (g_strcmp0 (method_name, "EEditorDialogDOMUnlink") == 0) {
+ } else if (g_strcmp0 (method_name, "EEditorLinkDialogOpen") == 0) {
+ g_variant_get (parameters, "(t)", &page_id);
+
+ editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
+ if (!editor_page)
+ goto error;
+
+ e_dialogs_dom_link_open (editor_page);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "EEditorLinkDialogClose") == 0) {
g_variant_get (parameters, "(t)", &page_id);
editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
if (!editor_page)
goto error;
+ e_dialogs_dom_link_close (editor_page);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "EEditorLinkDialogUnlink") == 0) {
+ EEditorUndoRedoManager *manager;
+
+ g_variant_get (parameters, "(t)", &page_id);
+
+ editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
+ if (!editor_page)
+ goto error;
+
+ manager = e_editor_page_get_undo_redo_manager (editor_page);
+ /* Remove the history event that was saved when the dialog was opened */
+ e_editor_undo_redo_manager_remove_current_history_event (manager);
+
e_editor_dom_selection_unlink (editor_page);
g_dbus_method_invocation_return_value (invocation, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]