diff options
author | Tomas Popela <tpopela@redhat.com> | 2014-07-21 19:56:58 +0800 |
---|---|---|
committer | Tomas Popela <tpopela@redhat.com> | 2014-07-21 20:17:19 +0800 |
commit | 61d338d55d9f077fe68beec38428cbf3aef24fae (patch) | |
tree | 157d333c573de1f0ba0b86f88a61995b49b528cf /e-util/e-html-editor-selection.c | |
parent | 7d5392d49b0337c8432bc96714f020aecf912a2b (diff) | |
download | gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar.gz gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar.bz2 gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar.lz gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar.xz gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.tar.zst gsoc2013-evolution-61d338d55d9f077fe68beec38428cbf3aef24fae.zip |
EHTMLEditorSelection - When wrapping the paragraph wrap just the text that is after the caret
The text before the caret is alredy wrapped so we don't have to rewrap
it again.
Diffstat (limited to 'e-util/e-html-editor-selection.c')
-rw-r--r-- | e-util/e-html-editor-selection.c | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c index 95188e8fbe..49353933c0 100644 --- a/e-util/e-html-editor-selection.c +++ b/e-util/e-html-editor-selection.c @@ -1567,9 +1567,14 @@ e_html_editor_selection_get_block_format (EHTMLEditorSelection *selection) } static gboolean -is_caret_position_node (WebKitDOMNode *node) +is_selection_position_node (WebKitDOMElement *element) { - return element_has_id (WEBKIT_DOM_ELEMENT (node), "-x-evo-caret-position"); + if (!element || !WEBKIT_DOM_IS_ELEMENT (element)) + return FALSE; + + return element_has_id (element, "-x-evo-caret-position") || + element_has_id (element, "-x-evo-selection-start-marker") || + element_has_id (element, "-x-evo-selection-end-marker"); } static void @@ -4997,36 +5002,49 @@ wrap_lines (EHTMLEditorSelection *selection, fragment, remove_all_br ? "br" : "br.-x-evo-wrap-br", NULL); + br_count = webkit_dom_node_list_get_length (wrap_br); + /* And remove them */ + for (ii = 0; ii < br_count; ii++) + remove_node (webkit_dom_node_list_item (wrap_br, ii)); } else { - WebKitDOMElement *caret_node; - if (!webkit_dom_node_has_child_nodes (paragraph)) return WEBKIT_DOM_ELEMENT (paragraph); paragraph_clone = webkit_dom_node_clone_node (paragraph, TRUE); - caret_node = webkit_dom_element_query_selector ( + element = webkit_dom_element_query_selector ( WEBKIT_DOM_ELEMENT (paragraph_clone), - "span#-x-evo-caret-position", NULL); + "span#-x-evo-caret-position", + NULL); text_content = webkit_dom_node_get_text_content (paragraph_clone); paragraph_char_count = g_utf8_strlen (text_content, -1); - if (caret_node) + if (element) paragraph_char_count--; g_free (text_content); - wrap_br = webkit_dom_element_query_selector_all ( + /* When we wrap, we are wrapping just the text after caret, text + * before the caret is already wrapped, so unwrap the text after + * the caret position */ + element = webkit_dom_element_query_selector ( WEBKIT_DOM_ELEMENT (paragraph_clone), - remove_all_br ? "br" : "br.-x-evo-wrap-br", + "span#-x-evo-selection-end-marker", NULL); - } - /* And remove them */ - br_count = webkit_dom_node_list_get_length (wrap_br); - for (ii = 0; ii < br_count; ii++) - remove_node (webkit_dom_node_list_item (wrap_br, ii)); + if (element) { + WebKitDOMNode *nd = WEBKIT_DOM_NODE (element); + + while (nd) { + WebKitDOMNode *next_nd = webkit_dom_node_get_next_sibling (nd); + if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) + remove_node (nd); + nd = next_nd; + } + } + } - if (selection) + if (selection) { node = WEBKIT_DOM_NODE (fragment); - else { + start_node = node; + } else { webkit_dom_node_normalize (paragraph_clone); node = webkit_dom_node_get_first_child (paragraph_clone); if (node) { @@ -5035,9 +5053,32 @@ wrap_lines (EHTMLEditorSelection *selection, node = webkit_dom_node_get_next_sibling (node); g_free (text_content); } + + /* We have to start from the end of the last wrapped line */ + element = webkit_dom_element_query_selector ( + WEBKIT_DOM_ELEMENT (paragraph_clone), + "span#-x-evo-selection-start-marker", + NULL); + + if (element) { + WebKitDOMNode *nd = WEBKIT_DOM_NODE (element); + + while ((nd = webkit_dom_node_get_previous_sibling (nd))) { + if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) { + element = WEBKIT_DOM_ELEMENT (nd); + break; + } else + element = NULL; + } + } + + if (element) { + node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)); + start_node = paragraph_clone; + } else + start_node = node; } - start_node = node; len = 0; while (node) { gint offset = 0; @@ -5068,8 +5109,6 @@ wrap_lines (EHTMLEditorSelection *selection, next_sibling = node; while (newline) { - WebKitDOMElement *element; - next_sibling = WEBKIT_DOM_NODE (webkit_dom_text_split_text ( WEBKIT_DOM_TEXT (next_sibling), g_utf8_pointer_to_offset (text_content, newline), @@ -5102,6 +5141,11 @@ wrap_lines (EHTMLEditorSelection *selection, } g_free (text_content); } else { + if (is_selection_position_node (WEBKIT_DOM_ELEMENT (node))) { + node = webkit_dom_node_get_next_sibling (node); + continue; + } + /* If element is ANCHOR we wrap it separately */ if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) { glong anchor_length; @@ -5136,11 +5180,6 @@ wrap_lines (EHTMLEditorSelection *selection, continue; } - if (is_caret_position_node (node)) { - node = webkit_dom_node_get_next_sibling (node); - continue; - } - /* When we are not removing user-entered BR elements (lines wrapped by user), * we need to skip those elements */ if (!remove_all_br && WEBKIT_DOM_IS_HTMLBR_ELEMENT (node)) { |