Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/9259

Vanessa4af11a358361
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 07f7e09247..04c3b09333 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -2,7 +2,7 @@ import {addScript, addScriptSync} from "../protyle/util/addScript";
import {Constants} from "../constants";
import {onMessage} from "./util/onMessage";
import {genUUID} from "../util/genID";
-import {hasClosestByAttribute, hasTopClosestByClassName} from "../protyle/util/hasClosest";
+import {hasClosestBlock, hasClosestByAttribute, hasTopClosestByClassName} from "../protyle/util/hasClosest";
import {Model} from "../layout/Model";
import "../assets/scss/mobile.scss";
import {Menus} from "../menus";
@@ -16,13 +16,15 @@ import {initMessage, showMessage} from "../dialog/message";
import {goBack} from "./util/MobileBackFoward";
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
import {getLocalStorage, writeText} from "../protyle/util/compatibility";
-import {openMobileFileById} from "./editor";
+import {getCurrentEditor, openMobileFileById} from "./editor";
import {getSearch} from "../util/functions";
import {initRightMenu} from "./menu";
import {openChangelog} from "../boot/openChangelog";
import {registerServiceWorker} from "../util/serviceWorker";
import {afterLoadPlugin, loadPlugins} from "../plugin/loader";
import {saveScroll} from "../protyle/scroll/saveScroll";
+import {removeBlock} from "../protyle/wysiwyg/remove";
+import {isNotEditBlock} from "../protyle/wysiwyg/getBlock";
class App {
public plugins: import("../plugin").Plugin[] = [];
@@ -68,7 +70,7 @@ class App {
}
});
window.addEventListener("beforeunload", () => {
- saveScroll(window.siyuan.mobile.editor.protyle);
+ saveScroll(window.siyuan.mobile.editor.protyle);
}, false);
window.addEventListener("pagehide", () => {
saveScroll(window.siyuan.mobile.editor.protyle);
@@ -108,6 +110,25 @@ class App {
document.addEventListener("touchend", (event) => {
handleTouchEnd(event, siyuanApp);
}, false);
+ // https://github.com/siyuan-note/siyuan/issues/9259
+ window.addEventListener("keydown", (event) => {
+ if (getSelection().rangeCount > 0) {
+ const range = getSelection().getRangeAt(0);
+ const editor = getCurrentEditor();
+ if (range.toString() === "" &&
+ editor && editor.protyle.wysiwyg.element.contains(range.startContainer) &&
+ !event.altKey && (event.key === "Backspace" || event.key === "Delete")) {
+ const nodeElement = hasClosestBlock(range.startContainer);
+ if (nodeElement && isNotEditBlock(nodeElement)) {
+ nodeElement.classList.add("protyle-wysiwyg--select");
+ removeBlock(editor.protyle, nodeElement, range);
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
+ }
+ }
+ })
});
}
}