Skip to content

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

:bug: Preserve cursor and keyboard when closing mobile block menus https://github.com/siyuan-note/siyuan/issues/19351

Daniel20a22180792b
diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts
index 2071a7e877..0dc12cd426 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -69,11 +69,21 @@ export class Menu {
this.element.addEventListener("focusin", activateKeymapInput);
this.element.addEventListener("pointerdown", activateKeymapInput);
if (isMobile()) {
+ const preserveBlockMenuFocus = (event: MouseEvent) => {
+ const name = this.element.getAttribute("data-name");
+ if ((name === Constants.MENU_BLOCK_SINGLE || name === Constants.MENU_BLOCK_MULTI) &&
+ !(event.target as Element).closest("input, textarea, select, [contenteditable=\"true\"]")) {
+ // 保留编辑器选区和键盘,同时允许菜单输入框正常获取焦点。
+ event.preventDefault();
+ }
+ };
+ this.element.addEventListener("mousedown", preserveBlockMenuFocus);
this.element.addEventListener("touchstart", this.handleSheetTouchStart, {passive: true});
this.element.addEventListener("touchmove", this.handleSheetTouchMove, {passive: false});
this.element.addEventListener("touchend", this.handleSheetTouchEnd);
this.element.addEventListener("touchcancel", this.handleSheetTouchCancel);
if (this.element.id === "commonMenu") {
+ document.getElementById("commonMenuScrim")?.addEventListener("mousedown", preserveBlockMenuFocus);
document.getElementById("commonMenuScrim")?.addEventListener("click", (event) => {
event.stopPropagation();
this.closeSheet();
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index 5eac118172..c9c3ad1491 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -1407,8 +1407,8 @@ export const initKeyboardToolbar = () => {
toolbarElement.addEventListener("mousedown", event => {
const buttonElement = hasClosestByTag(event.target as HTMLElement, "BUTTON");
const type = buttonElement && buttonElement.getAttribute("data-type");
- if (type === "undo" || type === "redo") {
- // 保持编辑器焦点,避免异步撤销或重做期间软键盘收起。
+ if (type === "undo" || type === "redo" || type === "block") {
+ // 保持编辑器焦点,避免工具栏操作期间软键盘收起。
event.preventDefault();
}
});
@@ -1690,12 +1690,12 @@ export const initKeyboardToolbar = () => {
window.JSAndroid?.hideKeyboard();
return;
} else if (type === "block") {
+ event.preventDefault();
protyle.toolbar.range = range;
keyboardPanelClosing = false;
hideKeyboardToolbarUtil();
protyle.gutter.renderMenu(protyle, nodeElement);
window.siyuan.menus.menu.fullscreen();
- activeBlur();
return;
} else if (type === "outdent") {
if (nodeElement.classList.contains("code-block")) {
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index b8efee26f7..f79da7637e 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -75,7 +75,7 @@ import {makeCard, quickMakeCard} from "../../card/makeCard";
import {transferBlockRef} from "../../menus/block";
import {isMobile} from "../../util/functions";
import {AIActions} from "../../ai/actions";
-import {activeBlur, renderTextMenu, showKeyboardToolbarUtil} from "../../mobile/util/keyboardToolbar";
+import {renderTextMenu, showKeyboardToolbarUtil} from "../../mobile/util/keyboardToolbar";
import {getMobileBlockSelectionElement} from "../../mobile/util/blockSelection";
import {hideTooltip} from "../../dialog/tooltip";
import {appearanceMenu, limitRecentFontStyleRows} from "../toolbar/Font";
@@ -1599,9 +1599,6 @@ export class Gutter {
}
hideElements(["util", "toolbar", "hint"], protyle);
window.siyuan.menus.menu.remove();
- if (isMobile()) {
- activeBlur();
- }
const id = buttonElement.getAttribute("data-node-id");
const nodeElement = this.getNodeElement(protyle, buttonElement);
if (!nodeElement) {