[evolution/gnome-3-38] I#1207 - Composer: Magic-links can reposition caret to incorrect place



commit d0e54f3975ab40f7c724744f7947a4179b7131d8
Author: Milan Crha <mcrha redhat com>
Date:   Thu Nov 5 16:55:30 2020 +0100

    I#1207 - Composer: Magic-links can reposition caret to incorrect place
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1207

 data/webkit/e-editor.js | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index e8ace1f68c..dbc0127141 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -3087,16 +3087,18 @@ EvoEditor.linkifyText = function(anchorNode, withUndo)
                parent = anchorNode.parentElement;
 
                for (ii = 0; ii < parts.length; ii++) {
-                       var part = parts[ii], node, isLast = ii + 1 >= parts.length;
+                       var part = parts[ii], node, isLast = ii + 1 >= parts.length, textLen = 
part.text.length;
 
                        if (part.href) {
                                node = document.createElement("A");
                                node.href = part.href;
                                node.innerText = part.text;
                        } else if (isLast) {
-                               node = null;
                                // it can be a space, which cannot be added after the element, thus 
workaround it this way
-                               newAnchorNode = anchorNode.splitText(matchEnd);
+                               node = anchorNode.splitText(matchEnd);
+                               if (!newAnchorNode && offset <= textLen)
+                                       newAnchorNode = node;
+                               node = null;
                        } else {
                                node = document.createTextNode(part.text);
                        }
@@ -3104,18 +3106,19 @@ EvoEditor.linkifyText = function(anchorNode, withUndo)
                        if (node)
                                parent.insertBefore(node, insBefore);
 
-                       if (!isLast) {
-                               matchEnd += part.text.length;
-                       } else if (node) {
+                       if (node && !newAnchorNode && offset <= textLen)
                                newAnchorNode = node;
-                       }
+                       else if (!newAnchorNode && offset > textLen)
+                               offset -= textLen;
+
+                       matchEnd += textLen;
                }
 
                if (anchorNode)
                        anchorNode.remove();
 
-               if (updateSelection && newAnchorNode && offset - matchEnd >= 0)
-                       selection.setPosition(newAnchorNode, offset - matchEnd);
+               if (updateSelection && newAnchorNode)
+                       selection.setPosition(newAnchorNode, offset);
        } finally {
                if (withUndo) {
                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "magicLink");


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