improve first letter checkup

This commit is contained in:
Peter Savchenko 2018-05-29 20:39:31 +03:00
commit 373579c27a
No known key found for this signature in database
GPG key ID: 63E739583C761566
3 changed files with 29 additions and 27 deletions

View file

@ -2569,6 +2569,19 @@ var Caret = function (_Module) {
anchorNode = selection.anchorNode,
firstNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent);
/**
* Workaround case when caret in the text link " |Hello!"
* selection.anchorOffset is 1, but real caret visible position is 0
* @type {number}
*/
var firstLetterPosition = anchorNode.textContent.search(/\S/);
if (firstLetterPosition === -1) {
// empty text
firstLetterPosition = 0;
}
/**
* In case of
* <div contenteditable>
@ -2583,26 +2596,13 @@ var Caret = function (_Module) {
return $.isEmpty(node);
});
/**
* Workaround case when caret in the text link " |Hello!"
* selection.anchorOffset is 1, but real caret visible position is 0
* @type {number}
*/
var firstLetterPosition = anchorNode.textContent.search(/\S/);
if (firstLetterPosition === -1) {
// empty text
firstLetterPosition = 0;
}
if (nothingAtLeft && selection.anchorOffset === firstLetterPosition) {
return true;
}
}
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === 0;
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === firstLetterPosition;
}
/**

File diff suppressed because one or more lines are too long

View file

@ -214,6 +214,19 @@ export default class Caret extends Module {
anchorNode = selection.anchorNode,
firstNode = $.getDeepestNode(this.Editor.BlockManager.currentBlock.pluginsContent);
/**
* Workaround case when caret in the text link " |Hello!"
* selection.anchorOffset is 1, but real caret visible position is 0
* @type {number}
*/
let firstLetterPosition = anchorNode.textContent.search(/\S/);
if (firstLetterPosition === -1) { // empty text
firstLetterPosition = 0;
}
/**
* In case of
* <div contenteditable>
@ -226,18 +239,7 @@ export default class Caret extends Module {
let leftSiblings = this.getHigherLevelSiblings(anchorNode, 'left'),
nothingAtLeft = leftSiblings.every( node => $.isEmpty(node) );
/**
* Workaround case when caret in the text link " |Hello!"
* selection.anchorOffset is 1, but real caret visible position is 0
* @type {number}
*/
let firstLetterPosition = anchorNode.textContent.search(/\S/);
if (firstLetterPosition === -1) { // empty text
firstLetterPosition = 0;
}
if (nothingAtLeft && selection.anchorOffset === firstLetterPosition) {
@ -247,7 +249,7 @@ export default class Caret extends Module {
}
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === 0;
return firstNode === null || anchorNode === firstNode && selection.anchorOffset === firstLetterPosition;
}