Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/15911

Vanessab96781004bec
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 7041f16d84..f83c23f43a 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -807,6 +807,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
}
+ const editElement = getContenteditableElement(nodeElement) as HTMLElement;
const imgSelectElement = protyle.wysiwyg.element.querySelector(".img--select");
if (imgSelectElement) {
imgSelectElement.classList.remove("img--select");
@@ -823,7 +824,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
return;
}
- const editElement = getContenteditableElement(nodeElement) as HTMLElement;
if (!editElement) {
nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(protyle, nodeElement, range, event.key === "Backspace" ? "Backspace" : "Delete");
@@ -1023,12 +1023,36 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
}
- } else if (nodeElement.classList.contains("code-block") && getContenteditableElement(nodeElement).textContent === "\n") {
+ } else if (nodeElement.classList.contains("code-block") && editElement.textContent === "\n") {
// 空代码块全选删除异常 https://github.com/siyuan-note/siyuan/issues/6706
range.collapse(true);
event.stopPropagation();
event.preventDefault();
return;
+ } else if (selectText !== "") {
+ const position = getSelectionOffset(editElement, protyle.wysiwyg.element, range);
+ if (range.startOffset === 0 && range.endContainer.textContent.length === range.endOffset) {
+ // 图片后为空格,在空格后删除 https://github.com/siyuan-note/siyuan/issues/13949
+ // 图片前有一个字符,在字符后删除 https://github.com/siyuan-note/siyuan/issues/15911
+ const rangePreviousElement = hasPreviousSibling(range.startContainer) as HTMLElement;
+ const rangeNextElement = hasNextSibling(range.endContainer) as HTMLElement;
+ if ((rangePreviousElement && rangePreviousElement.nodeType === 1 && rangePreviousElement.classList.contains("img") &&
+ rangeNextElement && rangeNextElement.nodeType === 1 && rangeNextElement.classList.contains("img")) ||
+ (position.start === 0 &&
+ range.startContainer.textContent !== Constants.ZWSP && // 如果为 zwsp 需前移光标
+ !rangePreviousElement &&
+ rangeNextElement && rangeNextElement.nodeType === 1 && rangeNextElement.classList.contains("img"))) {
+ range.insertNode(document.createElement("wbr"));
+ const oldHTML = nodeElement.outerHTML;
+ range.deleteContents();
+ range.insertNode(document.createTextNode(Constants.ZWSP));
+ range.insertNode(document.createElement("wbr"));
+ updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
+ focusByWbr(nodeElement, range);
+ event.preventDefault();
+ return;
+ }
+ }
}
}