mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Ignore ZWS when determining if at block boundary
These are just added to allow Chrome to focus an empty text node, but they should not be considered "real" content.
This commit is contained in:
parent
ee01d36a0f
commit
2d37608aac
1 changed files with 13 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
import { isInline, isBlock } from '../node/Category';
|
||||
import { getPreviousBlock, getNextBlock } from '../node/Block';
|
||||
import { getNodeBeforeOffset, getNodeAfterOffset } from '../node/Node';
|
||||
import { notWS } from '../Constants';
|
||||
import { ZWS, notWS } from '../Constants';
|
||||
import { isNodeContainedInRange } from './Boundaries';
|
||||
import { TreeIterator, SHOW_ELEMENT_OR_TEXT } from '../node/TreeIterator';
|
||||
|
||||
|
@ -82,9 +82,12 @@ const rangeDoesStartAtBlockBoundary = (
|
|||
|
||||
// If in the middle or end of a text node, we're not at the boundary.
|
||||
if (startContainer instanceof Text) {
|
||||
if (startOffset) {
|
||||
const text = startContainer.data;
|
||||
for (let i = startOffset; i > 0; i -= 1) {
|
||||
if (text.charAt(i - 1) !== ZWS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
nodeAfterCursor = startContainer;
|
||||
} else {
|
||||
nodeAfterCursor = getNodeAfterOffset(startContainer, startOffset);
|
||||
|
@ -121,12 +124,15 @@ const rangeDoesEndAtBlockBoundary = (range: Range, root: Element): boolean => {
|
|||
let currentNode: Node;
|
||||
|
||||
// If in a text node with content, and not at the end, we're not
|
||||
// at the boundary
|
||||
// at the boundary. Ignore ZWS.
|
||||
if (endContainer instanceof Text) {
|
||||
const length = endContainer.data.length;
|
||||
if (length && endOffset < length) {
|
||||
const text = endContainer.data;
|
||||
const length = text.length;
|
||||
for (let i = endOffset; i < length; i += 1) {
|
||||
if (text.charAt(i) !== ZWS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
currentNode = endContainer;
|
||||
} else {
|
||||
currentNode = getNodeBeforeOffset(endContainer, endOffset);
|
||||
|
|
Loading…
Reference in a new issue