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

Vanessae9aba04a3fb4
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 935b8b95cd..7041f16d84 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -833,8 +833,8 @@ 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/siyuan/issues/13949
if (range.startOffset === 0 && range.startContainer.textContent.length === 1) {
+ // 图片后为空格,在空格后删除 https://github.com/siyuan-note/siyuan/issues/13949
const rangePreviousElement = hasPreviousSibling(range.startContainer) as HTMLElement;
const rangeNextElement = hasNextSibling(range.startContainer) as HTMLElement;
if (rangePreviousElement && rangePreviousElement.nodeType === 1 && rangePreviousElement.classList.contains("img") &&
@@ -848,6 +848,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
return;
}
+ // 图片前有一个字符,在字符后删除 https://github.com/siyuan-note/siyuan/issues/15911
+ if (position.start === 0 &&
+ range.startContainer.textContent !== Constants.ZWSP && // 如果为 zwsp 需前移光标
+ !rangePreviousElement &&
+ rangeNextElement && rangeNextElement.nodeType === 1 && rangeNextElement.classList.contains("img")) {
+ const wbrElement = document.createElement("wbr");
+ range.insertNode(wbrElement);
+ const oldHTML = nodeElement.outerHTML;
+ wbrElement.nextSibling.textContent = Constants.ZWSP;
+ updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
+ focusByWbr(nodeElement, range);
+ event.preventDefault();
+ return;
+ }
}
// 需使用 innerText,否则 br 无法传唤为 /n https://github.com/siyuan-note/siyuan/issues/12066
// 段末反向删除 https://github.com/siyuan-note/insider/issues/274