mirror of
https://github.com/codex-team/editor.js
synced 2026-03-18 00:19:53 +01:00
improve first letter checkup
This commit is contained in:
parent
1f30fa2260
commit
373579c27a
3 changed files with 29 additions and 27 deletions
|
|
@ -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
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue