Vanessa 2024-08-28 18:27:00 +08:00
parent eeb3f9f4e7
commit 5a10723db9

View file

@ -798,7 +798,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
} else if (selectText === "") {
const editElement = getContenteditableElement(nodeElement);
const editElement = getContenteditableElement(nodeElement) as HTMLElement;
if (!editElement) {
nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(protyle, nodeElement, range, event.key === "Backspace" ? "Backspace" : "Delete");
@ -809,11 +809,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const position = getSelectionOffset(editElement, protyle.wysiwyg.element, range);
if (event.key === "Delete" || matchHotKey("⌃D", event)) {
// 段末反向删除 https://github.com/siyuan-note/insider/issues/274
if (position.end === editElement.textContent.length ||
if (position.end === editElement.innerText.length ||
// 软换行后删除 https://github.com/siyuan-note/siyuan/issues/11118
(position.end === editElement.textContent.length - 1 && editElement.textContent.endsWith("\n")) ||
(position.end === editElement.innerText.length - 1 && editElement.innerText.endsWith("\n")) ||
// 图片后无内容删除 https://github.com/siyuan-note/siyuan/issues/11868
(position.end === editElement.textContent.length - 1 && editElement.textContent.endsWith(Constants.ZWSP))) {
(position.end === editElement.innerText.length - 1 && editElement.innerText.endsWith(Constants.ZWSP))) {
const nextElement = getNextBlock(getTopAloneElement(nodeElement));
if (nextElement) {
const nextRange = focusBlock(nextElement);
@ -827,7 +827,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
return;
}
} else if (position.end === editElement.textContent.length - 1 && nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
} else if (position.end === editElement.innerText.length - 1 && nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
event.stopPropagation();
event.preventDefault();
return;
@ -850,7 +850,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const currentNode = range.startContainer.childNodes[range.startOffset - 1] as HTMLElement;
if (position.start === 0 && (
range.startOffset === 0 ||
(currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && currentNode.textContent === "") // https://ld246.com/article/1649251218696
(currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && currentNode.innerText === "") // https://ld246.com/article/1649251218696
)) {
removeBlock(protyle, nodeElement, range, "Backspace");
event.stopPropagation();
@ -884,15 +884,15 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const inlineElement = hasClosestByMatchTag(range.startContainer, "SPAN");
if (position.start === 2 && inlineElement &&
getSelectionOffset(inlineElement, protyle.wysiwyg.element, range).start === 1 &&
inlineElement.textContent.startsWith(Constants.ZWSP)) {
inlineElement.innerText.startsWith(Constants.ZWSP)) {
focusBlock(nodeElement);
event.stopPropagation();
event.preventDefault();
return;
}
if (position.start === 1 && !inlineElement && editElement.textContent.startsWith(Constants.ZWSP) &&
if (position.start === 1 && !inlineElement && editElement.innerText.startsWith(Constants.ZWSP) &&
// https://github.com/siyuan-note/siyuan/issues/12149
editElement.textContent.length > 1) {
editElement.innerText.length > 1) {
setFirstNodeRange(editElement, range);
removeBlock(protyle, nodeElement, range, "Backspace");
event.stopPropagation();