mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup some squire code
This commit is contained in:
parent
e9770e17f6
commit
6b42620ad3
1 changed files with 42 additions and 65 deletions
73
vendors/squire/build/squire-raw.js
vendored
73
vendors/squire/build/squire-raw.js
vendored
|
|
@ -220,52 +220,36 @@ const
|
|||
},
|
||||
|
||||
fixCursor = (node, root) => {
|
||||
// In Webkit and Gecko, block level elements are collapsed and
|
||||
// unfocusable if they have no content (:empty). To remedy this, a <BR> must be
|
||||
// inserted. In Opera and IE, we just need a textnode in order for the
|
||||
// cursor to appear.
|
||||
let self = root.__squire__;
|
||||
let originalNode = node;
|
||||
let fixer, child;
|
||||
|
||||
if (node === root) {
|
||||
if (!(child = node.firstChild) || child.nodeName === 'BR') {
|
||||
fixer = self.createDefaultBlock();
|
||||
if (child) {
|
||||
child.replaceWith(fixer);
|
||||
let fixer = null;
|
||||
if (node instanceof Text) {
|
||||
return node;
|
||||
}
|
||||
else {
|
||||
node.append(fixer);
|
||||
}
|
||||
node = fixer;
|
||||
fixer = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.nodeType === TEXT_NODE) {
|
||||
return originalNode;
|
||||
}
|
||||
|
||||
if (isInline(node)) {
|
||||
let child = node.firstChild;
|
||||
if (cantFocusEmptyTextNodes) {
|
||||
while (child && child instanceof Text && !child.data) {
|
||||
node.removeChild(child);
|
||||
child = node.firstChild;
|
||||
while (isWebKit && child?.nodeType === TEXT_NODE && !child.data) {
|
||||
child.remove();
|
||||
child = node.firstChild;
|
||||
}
|
||||
}
|
||||
if (!child) {
|
||||
fixer = self._addZWS();
|
||||
if (cantFocusEmptyTextNodes) {
|
||||
fixer = document.createTextNode(ZWS);
|
||||
} else {
|
||||
fixer = document.createTextNode("");
|
||||
}
|
||||
// } else if (!node.querySelector('BR')) {
|
||||
// } else if (!node.innerText.trim().length) {
|
||||
} else if (node.matches(':empty')) {
|
||||
fixer = createElement('BR');
|
||||
while ((child = node.lastElementChild) && !isInline(child)) {
|
||||
node = child;
|
||||
}
|
||||
} else if (node instanceof Element && !node.querySelector("BR")) {
|
||||
fixer = createElement("BR");
|
||||
let parent = node;
|
||||
let child;
|
||||
while ((child = parent.lastElementChild) && !isInline(child)) {
|
||||
parent = child;
|
||||
}
|
||||
}
|
||||
if (fixer) {
|
||||
try {
|
||||
node.append(fixer);
|
||||
node.appendChild(fixer);
|
||||
} catch (error) {
|
||||
didError({
|
||||
name: 'Squire: fixCursor – ' + error,
|
||||
|
|
@ -274,8 +258,7 @@ const
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
return originalNode;
|
||||
return node;
|
||||
},
|
||||
|
||||
// Recursively examine container nodes and wrap any inline children.
|
||||
|
|
@ -959,10 +942,7 @@ const
|
|||
let startBlock = getStartBlockOfRange(range, root);
|
||||
let nodeAfterCursor;
|
||||
|
||||
if (!startBlock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (startBlock) {
|
||||
// If in the middle or end of a text node, we're not at the boundary.
|
||||
if (startContainer.nodeType === TEXT_NODE) {
|
||||
if (startOffset) {
|
||||
|
|
@ -971,14 +951,10 @@ const
|
|||
nodeAfterCursor = startContainer;
|
||||
} else {
|
||||
nodeAfterCursor = getNodeAfter(startContainer, startOffset);
|
||||
if (nodeAfterCursor && !root.contains(nodeAfterCursor)) {
|
||||
nodeAfterCursor = null;
|
||||
}
|
||||
// The cursor was right at the end of the document
|
||||
if (!nodeAfterCursor) {
|
||||
if (!nodeAfterCursor || !root.contains(nodeAfterCursor)) {
|
||||
nodeAfterCursor = getNodeBefore(startContainer, startOffset);
|
||||
if (nodeAfterCursor.nodeType === TEXT_NODE &&
|
||||
nodeAfterCursor.length) {
|
||||
if (nodeAfterCursor.nodeType === TEXT_NODE && nodeAfterCursor.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -989,6 +965,7 @@ const
|
|||
contentWalker.currentNode = nodeAfterCursor;
|
||||
|
||||
return !contentWalker.previousNode();
|
||||
}
|
||||
},
|
||||
|
||||
rangeDoesEndAtBlockBoundary = (range, root) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue