This commit is contained in:
Murod Khaydarov 2018-05-24 21:19:22 +03:00
commit 550e3cec20
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
4 changed files with 16 additions and 5 deletions

View file

@ -534,7 +534,7 @@ var Dom = function () {
*
* @param {Node} node - root Node. From this vertex we start Deep-first search {@link https://en.wikipedia.org/wiki/Depth-first_search}
* @param {Boolean} atLast - find last text node
* @return {Node} - it can be text Node or Element Node, so that caret will able to work with it
* @return {Node|null} - it can be text Node or Element Node, so that caret will able to work with it
*/
}, {
@ -547,6 +547,11 @@ var Dom = function () {
var nodeChild = atLast ? node.lastChild : node.firstChild;
if (nodeChild.tagName === 'BR') {
nodeChild = nodeChild.nextSibling || nodeChild.parentNode.nextSibling;
}
return this.getDeepestNode(nodeChild, atLast);
}
@ -2535,7 +2540,7 @@ var Caret = function (_Module) {
anchorNode = selection.anchorNode,
firstNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent);
return anchorNode === firstNode && selection.anchorOffset === 0;
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === 0;
}
/**

File diff suppressed because one or more lines are too long

View file

@ -105,7 +105,7 @@ export default class Dom {
*
* @param {Node} node - root Node. From this vertex we start Deep-first search {@link https://en.wikipedia.org/wiki/Depth-first_search}
* @param {Boolean} atLast - find last text node
* @return {Node} - it can be text Node or Element Node, so that caret will able to work with it
* @return {Node|null} - it can be text Node or Element Node, so that caret will able to work with it
*/
static getDeepestNode(node, atLast = false) {
@ -113,6 +113,12 @@ export default class Dom {
let nodeChild = atLast ? node.lastChild : node.firstChild;
if (nodeChild.tagName === 'BR') {
nodeChild = nodeChild.nextSibling || nodeChild.parentNode.nextSibling;
}
return this.getDeepestNode(nodeChild, atLast);
}

View file

@ -154,7 +154,7 @@ export default class Caret extends Module {
anchorNode = selection.anchorNode,
firstNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent);
return anchorNode === firstNode && selection.anchorOffset === 0;
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === 0;
}