[evolution/wip/mcrha/webkit-jsc-api] Correct selection restore after magicLink



commit 22b98d5375c3bcf0369b479f7606283385e62755
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 30 17:36:14 2020 +0100

    Correct selection restore after magicLink

 data/webkit/e-editor.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 18412fe313..f278477e9a 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -2319,7 +2319,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                // the replace call below replaces &nbsp; (0xA0) with regular space
                match = EvoEditor.findPattern(text.replace(/ /g, " "), isEmail ? EvoEditor.EMAIL_PATTERN : 
EvoEditor.URL_PATTERN);
                if (match) {
-                       var url = text.substring(match.start, match.end), node, selection;
+                       var url = text.substring(match.start, match.end), node;
 
                        // because 'search' uses Regex and throws exception on brackets and other 
Regex-sensitive characters
                        var isInvalidTrailingChar = function(chr) {
@@ -2371,15 +2371,16 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                        }
 
                        if (url.length > 0) {
-                               selection = EvoSelection.Store(document);
-
                                EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "magicLink", 
baseNode.parentElement, baseNode.parentElement,
                                        EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML);
 
                                try {
+                                       var offset = selection.baseOffset, updateSelection = 
selection.baseNode === baseNode, newBaseNode;
+
                                        covered = true;
 
                                        baseNode.splitText(match.end);
+                                       newBaseNode = baseNode.nextSibling;
                                        baseNode.splitText(match.start);
 
                                        baseNode = baseNode.nextSibling;
@@ -2395,7 +2396,8 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                                        baseNode.parentElement.insertBefore(node, baseNode);
                                        node.appendChild(baseNode);
 
-                                       EvoSelection.Restore(document, selection);
+                                       if (updateSelection && newBaseNode && offset - match.end >= 0)
+                                               selection.setPosition(newBaseNode, offset - match.end);
                                } finally {
                                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "magicLink");
                                        EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]