Skip to content

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

:bug: Restore keyboard when dismissing mobile editor menus https://github.com/siyuan-note/siyuan/issues/19427

Daniel4685f39f5636
diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts
index 4acd75bfce..618df8b0ad 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -41,6 +41,7 @@ export class Menu {
private suppressSheetClick = false;
private targetPositionFrame: number | undefined;
private cancelSheetOpen: (() => void) | undefined;
+ private restoreKeyboard: (() => void) | undefined;
private updateTargetPosition = () => {
if (typeof this.targetPositionFrame === "number") {
@@ -301,7 +302,7 @@ export class Menu {
this.finishSheetTouch();
};
- private closeSheet() {
+ public closeSheet() {
this.cancelSheetOpen?.();
this.cancelSheetOpen = undefined;
if (!this.element.classList.contains("b3-menu--sheet")) {
@@ -315,6 +316,10 @@ export class Menu {
this.element.style.transform = "translateY(100%)";
this.hideFullscreenScrim();
fullscreenCloseTimeout = window.setTimeout(() => this.removeImmediately(), Constants.TIMEOUT_DBLCLICK);
+ const restoreKeyboard = this.restoreKeyboard;
+ this.restoreKeyboard = undefined;
+ // 在关闭手势中恢复焦点,使浏览器端也能响应用户操作弹出软键盘。
+ restoreKeyboard?.();
}
private updateSheetTitle() {
@@ -449,6 +454,10 @@ export class Menu {
}
return;
}
+ if (isMobile()) {
+ this.closeSheet();
+ return;
+ }
}
this.removeImmediately();
}
@@ -470,6 +479,8 @@ export class Menu {
}
private removeImmediately() {
+ // 菜单动作和菜单替换只清理状态,避免跳转或弹窗后抢回编辑焦点。
+ this.restoreKeyboard = undefined;
this.cancelSheetOpen?.();
this.cancelSheetOpen = undefined;
const menuName = this.element.getAttribute("data-name");
@@ -607,7 +618,7 @@ export class Menu {
}
}
- public fullscreen(position: "bottom" | "all" = "all") {
+ public fullscreen(position: "bottom" | "all" = "all", restoreKeyboard?: () => void) {
this.cancelSheetOpen?.();
this.cancelSheetOpen = undefined;
applyMenuConfig(this.element);
@@ -639,6 +650,7 @@ export class Menu {
return;
}
// 先结束编辑焦点,避免工具栏保留的焦点阻止输入法收起,再跳过键盘弹出保护锁。
+ this.restoreKeyboard = restoreKeyboard;
(document.activeElement as HTMLElement)?.blur();
activeBlur(true);
clearTimeout(fullscreenCloseTimeout);
diff --git a/app/src/menus/menuKeyboardRestore.test.ts b/app/src/menus/menuKeyboardRestore.test.ts
new file mode 100644
index 0000000000..33adfd4d91
--- /dev/null
+++ b/app/src/menus/menuKeyboardRestore.test.ts
@@ -0,0 +1,156 @@
+import {readFileSync} from "node:fs";
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {runInNewContext} from "node:vm";
+import {createSourceFile, isClassDeclaration, ModuleKind, ScriptTarget, transpileModule} from "typescript";
+import type {Menu} from "./Menu";
+import {waitForSheetViewport} from "./sheetOpen";
+
+const source = createSourceFile("Menu.ts", readFileSync("src/menus/Menu.ts", "utf8"), ScriptTarget.ES2021, true);
+const declaration = source.statements.find(statement => isClassDeclaration(statement) && statement.name?.text === "Menu");
+const compiled = transpileModule(declaration.getText(source), {
+ compilerOptions: {target: ScriptTarget.ES2021, module: ModuleKind.CommonJS},
+}).outputText;
+
+const createElement = () => {
+ const classes = new Set<string>();
+ const attributes = new Map<string, string>();
+ return {
+ style: {} as CSSStyleDeclaration,
+ innerHTML: "items",
+ scrollTop: 0,
+ offsetHeight: 480,
+ classList: {
+ add: (...names: string[]) => names.forEach(name => classes.add(name)),
+ remove: (...names: string[]) => names.forEach(name => classes.delete(name)),
+ contains: (name: string) => classes.has(name),
+ },
+ getAttribute: (name: string) => attributes.get(name),
+ removeAttribute: (name: string) => attributes.delete(name),
+ };
+};
+
+const setup = () => {
+ let time = 0;
+ let height = 476;
+ let sequence = 0;
+ const timers = new Map<number, () => void>();
+ const frames = new Map<number, () => void>();
+ const events: string[] = [];
+ const first = {...createElement(), querySelector: () => ({innerHTML: ""})};
+ const element = {
+ ...createElement(),
+ firstElementChild: first,
+ lastElementChild: createElement(),
+ querySelectorAll: () => [] as Element[],
+ };
+ const module = {exports: {} as {Menu: typeof Menu}};
+ runInNewContext(compiled, {
+ exports: module.exports,
+ fullscreenCloseTimeout: undefined,
+ isMobile: () => true,
+ applyMenuConfig: () => {},
+ updateMenuItemGroupClasses: () => {},
+ activeBlur: (force: boolean) => events.push(force ? "hide-forced" : "hide"),
+ waitForSheetViewport,
+ clearTimeout: (id: number) => timers.delete(id),
+ requestAnimationFrame: (callback: () => void) => { frames.set(++sequence, callback); return sequence; },
+ cancelAnimationFrame: (id: number) => frames.delete(id),
+ performance: {now: () => time},
+ document: {activeElement: {blur: () => events.push("blur")}},
+ Constants: {TIMEOUT_DBLCLICK: 200},
+ window: {
+ get innerHeight() { return height; },
+ siyuan: {
+ zIndex: 0,
+ languages: {back: "Back"},
+ mobile: {size: {portrait: {height1: 808}}},
+ },
+ addEventListener: () => {},
+ setTimeout: (callback: () => void) => { timers.set(++sequence, callback); return sequence; },
+ },
+ });
+ const menu = Object.create(module.exports.Menu.prototype) as Menu;
+ Object.assign(menu, {
+ element,
+ stopTrackingTargetPosition: () => {},
+ emitCommonMenu: () => {},
+ showFullscreenScrim: () => {},
+ hideFullscreenScrim: () => {},
+ setSheetHeight: () => {},
+ finishSheetTouch: () => {},
+ removeScrollEvent: () => {},
+ });
+ return {
+ menu, element, events,
+ tick(nextTime: number, nextHeight = height) {
+ time = nextTime;
+ height = nextHeight;
+ const callbacks = Array.from(frames.values());
+ frames.clear();
+ callbacks.forEach(callback => callback());
+ },
+ finishClose() {
+ const callbacks = Array.from(timers.values());
+ timers.clear();
+ callbacks.forEach(callback => callback());
+ },
+ };
+};
+
+describe("mobile menu keyboard lifecycle", () => {
+ it("still hides the keyboard and waits for the restored viewport before opening", () => {
+ const {menu, element, events, tick} = setup();
+ menu.fullscreen("all", () => events.push("restore"));
+ assert.deepEqual(events, ["blur", "hide-forced"]);
+ tick(16);
+ tick(400, 700);
+ assert.equal(element.style.transform, "translateY(100%)");
+ tick(500, 808);
+ tick(532);
+ assert.equal(element.style.transform, "translateY(0px)");
+ assert.equal(events.includes("restore"), false);
+ });
+
+ it("restores once during the dismissal gesture, before the closing timer runs", () => {
+ const {menu, events, finishClose} = setup();
+ menu.fullscreen("all", () => events.push("restore"));
+ menu.closeSheet();
+ assert.deepEqual(events, ["blur", "hide-forced", "restore"]);
+ menu.closeSheet();
+ finishClose();
+ assert.equal(events.filter(event => event === "restore").length, 1);
+ });
+
+ it("restores on system back but leaves submenu back navigation alone", () => {
+ const {menu, events, element} = setup();
+ menu.fullscreen("all", () => events.push("restore"));
+ const submenu = {...createElement(), querySelector: (): Element => undefined};
+ element.querySelectorAll = () => [submenu as unknown as Element];
+ menu.remove(true);
+ assert.equal(events.includes("restore"), false);
+ element.querySelectorAll = () => [];
+ menu.remove(true);
+ assert.equal(events.includes("restore"), true);
+ });
+
+ it("discards restoration on menu actions and internal removal", () => {
+ const {menu, events} = setup();
+ menu.fullscreen("all", () => events.push("restore"));
+ menu.remove();
+ menu.closeSheet();
+ assert.equal(events.includes("restore"), false);
+ });
+
+ it("cancels the old closing timer when another menu opens", () => {
+ const {menu, element, events, finishClose} = setup();
+ menu.fullscreen("all", () => events.push("restore-first"));
+ menu.closeSheet();
+ menu.fullscreen("all", () => events.push("restore-second"));
+ finishClose();
+ assert.equal(element.classList.contains("fn__none"), false);
+ menu.closeSheet();
+ assert.equal(events.filter(event => event === "restore-first").length, 1);
+ assert.equal(events.filter(event => event === "restore-second").length, 1);
+ });
+});
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index caed123e03..29dc8a9519 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -71,6 +71,8 @@ import {
} from "../../protyle/toolbar/fontFamilyMenu";
import {notifyMobileKeyboardChange} from "./mobileKeyboardChange";
import {getEditorFocusRange, restoreEditorFocusRange} from "../../protyle/util/editorFocus";
+import {captureMenuKeyboard} from "./menuKeyboard";
+import {isMobile} from "../../util/functions";
import {createFontSizePicker} from "../../protyle/toolbar/fontControls";
import {applyMobileToolbarEntries} from "./toolbarEntries";
import {getEntryOrder, isEntryVisible} from "../../config/entryVisibility/runtime";
@@ -869,6 +871,32 @@ const restoreKeyboardToolbarRange = (protyle: IProtyle | undefined, range?: Rang
}
};
+export const bindMobileMenuKeyboard = (element: HTMLElement, selector: string, getProtyle: () => IProtyle) => {
+ let restoreKeyboard: (() => void) | undefined;
+ if (isMobile()) {
+ // 在按钮默认行为改变焦点之前保存状态,异步菜单请求使用本次操作独立的恢复回调。
+ element.addEventListener("pointerdown", event => {
+ restoreKeyboard = undefined;
+ if (!(event.target as Element).closest(selector)) {
+ return;
+ }
+ const protyle = getProtyle();
+ const toolbarElement = document.getElementById("keyboardToolbar");
+ restoreKeyboard = captureMenuKeyboard({
+ protyle,
+ keyboardOpen: Boolean(toolbarElement && !toolbarElement.classList.contains("fn__none") && !showUtil),
+ isCurrent: () => getCurrentEditor()?.protyle === protyle,
+ restore: range => restoreKeyboardToolbarRange(protyle, range),
+ });
+ }, true);
+ }
+ return () => {
+ const restore = restoreKeyboard;
+ restoreKeyboard = undefined;
+ return restore;
+ };
+};
+
const renderKeyboardToolbar = () => {
if (renderKeyboardToolbarFrame !== undefined) {
return;
@@ -1417,6 +1445,8 @@ export const initKeyboardToolbar = () => {
let startY = 0;
let startX = 0;
let moved = false;
+ const takeMenuKeyboard = bindMobileMenuKeyboard(toolbarElement, 'button[data-type="block"]',
+ () => getCurrentEditor()?.protyle);
toolbarElement.addEventListener("touchstart", e => {
startY = e.touches[0].clientY;
startX = e.touches[0].clientX;
@@ -1436,6 +1466,7 @@ export const initKeyboardToolbar = () => {
}
});
toolbarElement.addEventListener(isInAndroid() || isInHarmony() ? "touchend" : "click", async (event) => {
+ const restoreMenuKeyboard = takeMenuKeyboard();
if (moved) {
return;
}
@@ -1721,7 +1752,7 @@ export const initKeyboardToolbar = () => {
keyboardPanelClosing = false;
hideKeyboardToolbarUtil();
protyle.gutter.renderMenu(protyle, nodeElement);
- window.siyuan.menus.menu.fullscreen();
+ window.siyuan.menus.menu.fullscreen("all", restoreMenuKeyboard);
return;
} else if (type === "outdent") {
if (nodeElement.classList.contains("code-block")) {
diff --git a/app/src/mobile/util/menuKeyboard.test.ts b/app/src/mobile/util/menuKeyboard.test.ts
new file mode 100644
index 0000000000..f23237a2e2
--- /dev/null
+++ b/app/src/mobile/util/menuKeyboard.test.ts
@@ -0,0 +1,154 @@
+import {afterEach, describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {captureMenuKeyboard} from "./menuKeyboard";
+
+class TestElement {
+ public isConnected = true;
+ public visible = true;
+
+ constructor(public parentElement?: TestElement) {
+ }
+
+ public contains(node: TestElement) {
+ while (node) {
+ if (node === this) {
+ return true;
+ }
+ node = node.parentElement;
+ }
+ return false;
+ }
+
+ public getClientRects() {
+ return this.visible ? [{}] : [];
+ }
+}
+
+const originalDocument = globalThis.document;
+afterEach(() => {
+ globalThis.document = originalDocument;
+});
+
+const setup = () => {
+ const body = new TestElement();
+ const editor = new TestElement(body);
+ const text = new TestElement(editor);
+ const menu = new TestElement(body);
+ const input = new TestElement(menu);
+ const range = {
+ startContainer: text,
+ endContainer: text,
+ startOffset: 2,
+ endOffset: 4,
+ cloneRange() {
+ return {...this};
+ },
+ };
+ const state = {
+ activeElement: editor,
+ rangeCount: 1,
+ current: true,
+ dialogs: [] as TestElement[],
+ restored: [] as Range[],
+ };
+ globalThis.document = {
+ body,
+ get activeElement() { return state.activeElement; },
+ getSelection: () => ({rangeCount: state.rangeCount, getRangeAt: () => range}),
+ getElementById: () => menu,
+ querySelectorAll: () => state.dialogs,
+ } as unknown as Document;
+ const protyle = {
+ wysiwyg: {element: editor},
+ block: {rootID: "doc-a"},
+ toolbar: {range: undefined},
+ disabled: false,
+ } as unknown as IProtyle;
+ const capture = (keyboardOpen = true) => captureMenuKeyboard({
+ protyle,
+ keyboardOpen,
+ isCurrent: () => state.current,
+ restore: saved => state.restored.push(saved),
+ });
+ return {body, editor, text, menu, input, range, state, protyle, capture};
+};
+
+describe("mobile menu keyboard restoration", () => {
+ it("restores the captured selection once after keyboard dismissal clears the live selection", () => {
+ const {body, state, protyle, capture} = setup();
+ const restore = capture();
+ state.activeElement = body;
+ state.rangeCount = 0;
+ restore();
+ restore();
+ assert.equal(state.restored.length, 1);
+ assert.equal(state.restored[0].startOffset, 2);
+ assert.equal(state.restored[0].endOffset, 4);
+ assert.equal(protyle.toolbar.range, state.restored[0]);
+ });
+
+ it("does not open a previously closed keyboard or use an unfocused editor's stale selection", () => {
+ const {body, state, capture} = setup();
+ assert.equal(capture(false), undefined);
+ state.activeElement = new TestElement(body);
+ assert.equal(capture(), undefined);
+ });
+
+ it("does not capture a selection outside the editor", () => {
+ const {body, range, capture} = setup();
+ range.endContainer = new TestElement(body);
+ assert.equal(capture(), undefined);
+ });
+
+ it("allows dismissal of a menu input without stealing focus from another input", () => {
+ for (const inMenu of [true, false]) {
+ const {body, input, state, capture} = setup();
+ const restore = capture();
+ state.activeElement = inMenu ? input : new TestElement(body);
+ restore();
+ assert.equal(state.restored.length, inMenu ? 1 : 0);
+ }
+ });
+
+ it("cancels restoration after navigation, editor replacement, readonly mode, hiding or deletion", () => {
+ const changes = [
+ (test: ReturnType<typeof setup>) => { test.protyle.block.rootID = "doc-b"; },
+ (test: ReturnType<typeof setup>) => { test.state.current = false; },
+ (test: ReturnType<typeof setup>) => { test.protyle.disabled = true; },
+ (test: ReturnType<typeof setup>) => { test.editor.visible = false; },
+ (test: ReturnType<typeof setup>) => { test.editor.isConnected = false; },
+ (test: ReturnType<typeof setup>) => { test.text.isConnected = false; },
+ (test: ReturnType<typeof setup>) => { test.text.parentElement = test.body; },
+ ];
+ for (const change of changes) {
+ const test = setup();
+ const restore = test.capture();
+ change(test);
+ restore();
+ assert.equal(test.state.restored.length, 0);
+ }
+ });
+
+ it("does not restore a live Range that was retargeted when its source node was removed", () => {
+ const test = setup();
+ let saved: typeof test.range;
+ test.range.cloneRange = () => {
+ saved = {...test.range};
+ return saved;
+ };
+ const restore = test.capture();
+ saved.startContainer = test.editor;
+ saved.endContainer = test.editor;
+ restore();
+ assert.equal(test.state.restored.length, 0);
+ });
+
+ it("does not steal focus when an action opens a new dialog", () => {
+ const {body, state, capture} = setup();
+ const restore = capture();
+ state.activeElement = body;
+ state.dialogs.push(new TestElement(body));
+ restore();
+ assert.equal(state.restored.length, 0);
+ });
+});
diff --git a/app/src/mobile/util/menuKeyboard.ts b/app/src/mobile/util/menuKeyboard.ts
new file mode 100644
index 0000000000..83291d504c
--- /dev/null
+++ b/app/src/mobile/util/menuKeyboard.ts
@@ -0,0 +1,48 @@
+import {getEditorFocusRange} from "../../protyle/util/editorFocus";
+
+export const captureMenuKeyboard = (options: {
+ protyle: IProtyle,
+ keyboardOpen: boolean,
+ isCurrent: () => boolean,
+ restore: (range: Range) => void,
+}) => {
+ const {protyle} = options;
+ const editorElement = protyle?.wysiwyg.element;
+ if (!options.keyboardOpen || !editorElement?.contains(document.activeElement) || protyle.disabled) {
+ return;
+ }
+ const selection = document.getSelection();
+ const range = getEditorFocusRange(editorElement, selection?.rangeCount ? selection.getRangeAt(0) : undefined);
+ if (!range) {
+ return;
+ }
+ const rootID = protyle.block.rootID;
+ const startContainer = range.startContainer;
+ const endContainer = range.endContainer;
+ const dialogs = new Set(document.querySelectorAll(".b3-dialog--open"));
+ let restored = false;
+ return () => {
+ if (restored) {
+ return;
+ }
+ restored = true;
+ // 选区节点删除后,浏览器会把 Range 移到父节点,不能据此恢复到其他位置。
+ if (!options.isCurrent() || protyle.disabled || protyle.block.rootID !== rootID ||
+ !editorElement.isConnected || editorElement.getClientRects().length === 0 ||
+ !startContainer.isConnected || !endContainer.isConnected ||
+ range.startContainer !== startContainer || range.endContainer !== endContainer ||
+ !getEditorFocusRange(editorElement, range)) {
+ return;
+ }
+ const activeElement = document.activeElement;
+ if (activeElement && activeElement !== document.body && !editorElement.contains(activeElement) &&
+ !document.getElementById("commonMenu")?.contains(activeElement)) {
+ return;
+ }
+ if (Array.from(document.querySelectorAll(".b3-dialog--open")).some(dialog => !dialogs.has(dialog))) {
+ return;
+ }
+ protyle.toolbar.range = range;
+ options.restore(range);
+ };
+};
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index bf54cd1f0b..51d3233d5f 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -42,6 +42,7 @@ import {genEmbedStatTip, type IBlockStat, type IEmbedStat} from "../../layout/st
import {mountBreadcrumbButtons} from "../../plugin/breadcrumbButton";
import {getHostCapabilities} from "../../util/hostCapabilities";
import {waitForPendingTransactions} from "../util/transactionQueue";
+import {bindMobileMenuKeyboard} from "../../mobile/util/keyboardToolbar";
const genDocumentStatLabel = (stat: IBlockStat, statWithEmbed?: IBlockStat, embedStat?: IEmbedStat) => {
const runeEmbedAttrs = statWithEmbed ? ` class="ariaLabel" data-position="north" aria-label="${escapeAriaLabel(genEmbedStatTip(window.siyuan.languages.runeCountWithEmbed, statWithEmbed.runeCount, embedStat))}"` : "";
@@ -90,7 +91,10 @@ ${padHTML}
<button class="block__icon fn__flex-center fn__none ariaLabel" data-type="context" aria-label="${window.siyuan.languages.context}"><svg><use xlink:href="#iconAlignCenter"></use></svg></button>`;
this.element = element.firstElementChild as HTMLElement;
mountBreadcrumbButtons(protyle, element.querySelector(".protyle-breadcrumb__plugin"));
+ const takeMenuKeyboard = bindMobileMenuKeyboard(element,
+ 'button[data-type="mobile-menu"], button[data-type="doc"], button[data-type="more"]', () => protyle);
element.addEventListener("click", async (event) => {
+ const restoreMenuKeyboard = takeMenuKeyboard();
let target = event.target as HTMLElement;
if (event.composedPath().some(item => item instanceof HTMLElement && item.hasAttribute("data-plugin-name"))) {
return;
@@ -129,7 +133,7 @@ ${padHTML}
event.preventDefault();
break;
} else if (type === "mobile-menu") {
- this.genMobileMenu(protyle);
+ this.genMobileMenu(protyle, restoreMenuKeyboard);
event.preventDefault();
event.stopPropagation();
break;
@@ -147,7 +151,8 @@ ${padHTML}
});
} else {
const targetRect = target.getBoundingClientRect();
- openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, h: targetRect.height, isLeft: true}, Constants.MENU_FROM_TITLE_BREADCRUMB);
+ openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, h: targetRect.height, isLeft: true},
+ Constants.MENU_FROM_TITLE_BREADCRUMB, restoreMenuKeyboard);
}
event.stopPropagation();
event.preventDefault();
@@ -159,7 +164,7 @@ ${padHTML}
y: targetRect.bottom,
h: targetRect.height,
isLeft: true,
- });
+ }, restoreMenuKeyboard);
event.stopPropagation();
event.preventDefault();
break;
@@ -617,10 +622,14 @@ ${padHTML}
});
}
- private async genMobileMenu(protyle: IProtyle) {
+ private async genMobileMenu(protyle: IProtyle, restoreKeyboard?: () => void) {
if (protyle.lite || protyle.toolbar.isMultiSelectMode() || this.mobileMenuLoading) {
return;
}
+ if (window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_BREADCRUMB_MOBILE_PATH) {
+ window.siyuan.menus.menu.closeSheet();
+ return;
+ }
const menu = new Menu(Constants.MENU_BREADCRUMB_MOBILE_PATH);
if (menu.isOpen) {
return;
@@ -669,7 +678,7 @@ ${padHTML}
}
});
});
- menu.fullscreen();
+ window.siyuan.menus.menu.fullscreen("all", restoreKeyboard);
}).finally(() => {
this.mobileMenuLoading = false;
});
@@ -684,11 +693,15 @@ ${padHTML}
}
}
- public async showMenu(protyle: IProtyle, position: IPosition) {
+ public async showMenu(protyle: IProtyle, position: IPosition, restoreKeyboard?: () => void) {
const requestID = ++this.menuRequestID;
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_BREADCRUMB_MORE) {
- window.siyuan.menus.menu.remove();
+ if (isMobile()) {
+ window.siyuan.menus.menu.closeSheet();
+ } else {
+ window.siyuan.menus.menu.remove();
+ }
return;
}
let id;
@@ -1111,7 +1124,7 @@ ${padHTML}
});
}
/// #if MOBILE
- window.siyuan.menus.menu.fullscreen();
+ window.siyuan.menus.menu.fullscreen("all", restoreKeyboard);
/// #else
window.siyuan.menus.menu.popup(position);
/// #endif
diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts
index a54a7186b9..5d922a7871 100644
--- a/app/src/protyle/header/openTitleMenu.ts
+++ b/app/src/protyle/header/openTitleMenu.ts
@@ -31,12 +31,17 @@ import {buildBlockDOMClipboardRichData} from "../util/blockDOMClipboard";
import {buildWebClipboardHTML} from "../util/clipboardData";
import {exportImage} from "../export/util";
import {getHostCapabilities} from "../../util/hostCapabilities";
+import {isMobile} from "../../util/functions";
-export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: string) => {
+export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: string, restoreKeyboard?: () => void) => {
hideTooltip();
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_TITLE) {
- window.siyuan.menus.menu.remove();
+ if (isMobile()) {
+ window.siyuan.menus.menu.closeSheet();
+ } else {
+ window.siyuan.menus.menu.remove();
+ }
return;
}
const docInfoParam: BlockQueryRequestInput = {
@@ -370,7 +375,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: stri
label: `${window.siyuan.languages.modifiedAt} ${dayjs(response.data.ial.updated).format("YYYY-MM-DD HH:mm:ss")}<br>${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`
}).element);
/// #if MOBILE
- window.siyuan.menus.menu.fullscreen();
+ window.siyuan.menus.menu.fullscreen("all", restoreKeyboard);
/// #else
window.siyuan.menus.menu.popup(position);
/// #endif