MDL-71047 HTML Editor (Atto): Cursor position is not correct when paste

This commit is contained in:
Nhan Vo
2021-05-18 10:05:48 +07:00
parent 486ba9af35
commit 16fe2bdc5e
5 changed files with 21 additions and 30 deletions
@@ -1485,17 +1485,9 @@ EditorClean.prototype = {
// Scrub the paste content.
content = this._cleanPasteHTML(content);
// Save the current selection.
// Using saveSelection as it produces a more consistent experience.
var selection = window.rangy.saveSelection();
// Insert the content.
this.insertContentAtFocusPoint(content);
// Restore the selection, and collapse to end.
window.rangy.restoreSelection(selection);
window.rangy.getSelection().collapseToEnd();
// Update the text area.
this.updateOriginal();
return false;
@@ -2826,7 +2818,12 @@ EditorSelection.prototype = {
}
if (range) {
range.deleteContents();
range.insertNode(node.getDOMNode());
range.collapse(false);
var currentnode = node.getDOMNode(),
last = currentnode.lastChild || currentnode;
range.insertNode(currentnode);
range.collapseAfter(last);
selection.setSingleRange(range);
}
return node;
}
File diff suppressed because one or more lines are too long
@@ -1474,17 +1474,9 @@ EditorClean.prototype = {
// Scrub the paste content.
content = this._cleanPasteHTML(content);
// Save the current selection.
// Using saveSelection as it produces a more consistent experience.
var selection = window.rangy.saveSelection();
// Insert the content.
this.insertContentAtFocusPoint(content);
// Restore the selection, and collapse to end.
window.rangy.restoreSelection(selection);
window.rangy.getSelection().collapseToEnd();
// Update the text area.
this.updateOriginal();
return false;
@@ -2801,7 +2793,12 @@ EditorSelection.prototype = {
}
if (range) {
range.deleteContents();
range.insertNode(node.getDOMNode());
range.collapse(false);
var currentnode = node.getDOMNode(),
last = currentnode.lastChild || currentnode;
range.insertNode(currentnode);
range.collapseAfter(last);
selection.setSingleRange(range);
}
return node;
}
-8
View File
@@ -190,17 +190,9 @@ EditorClean.prototype = {
// Scrub the paste content.
content = this._cleanPasteHTML(content);
// Save the current selection.
// Using saveSelection as it produces a more consistent experience.
var selection = window.rangy.saveSelection();
// Insert the content.
this.insertContentAtFocusPoint(content);
// Restore the selection, and collapse to end.
window.rangy.restoreSelection(selection);
window.rangy.getSelection().collapseToEnd();
// Update the text area.
this.updateOriginal();
return false;
+6 -1
View File
@@ -409,7 +409,12 @@ EditorSelection.prototype = {
}
if (range) {
range.deleteContents();
range.insertNode(node.getDOMNode());
range.collapse(false);
var currentnode = node.getDOMNode(),
last = currentnode.lastChild || currentnode;
range.insertNode(currentnode);
range.collapseAfter(last);
selection.setSingleRange(range);
}
return node;
}