Skip to content

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

:bug: Restore mobile bottom bar after closing panels https://github.com/siyuan-note/siyuan/issues/19150

Daniel8146823e2bf0
diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.ts
index f4fcf837eb..5d4103b034 100644
--- a/app/src/boot/globalEvent/command/panel.ts
+++ b/app/src/boot/globalEvent/command/panel.ts
@@ -12,6 +12,9 @@ import {ensureCommandSystem, executeCommandById} from "../../../command/executor
import {initializeEnglishCommandTranslations} from "../../../command/english";
import {createPaletteFocusLifecycle, queryCommandPalette} from "../../../command/paletteCore";
import type {ICommandContextSnapshot, ICommandDefinition} from "../../../command/types";
+/// #if MOBILE
+import {activeBlur} from "../../../mobile/util/keyboardToolbar";
+/// #endif
const renderCommands = (listElement: HTMLElement, commands: ICommandDefinition[]) => {
const fragment = document.createDocumentFragment();
@@ -47,6 +50,7 @@ export const commandPanel = (app: App) => {
}
const context = captureCommandContext({app, source: "commandPanel"});
const registry = ensureCommandSystem(app);
+ const restoreFocusAfterCancel = !isMobile() || document.body.classList.contains("mobile-keyboard--open");
const focusLifecycle = createPaletteFocusLifecycle(() => {
if (context.range?.startContainer.isConnected) {
focusByRange(context.range);
@@ -70,7 +74,12 @@ export const commandPanel = (app: App) => {
</div>`,
disableAnimation: true,
destroyCallback() {
- focusLifecycle.restoreAfterCancel();
+ const canceled = focusLifecycle.restoreAfterCancel(restoreFocusAfterCancel);
+ /// #if MOBILE
+ if (canceled && !restoreFocusAfterCancel) {
+ activeBlur(true);
+ }
+ /// #endif
},
});
dialog.element.setAttribute("data-key", Constants.DIALOG_COMMANDPANEL);
diff --git a/app/src/command/paletteCore.test.ts b/app/src/command/paletteCore.test.ts
index d0240ae6d4..e2aada2102 100644
--- a/app/src/command/paletteCore.test.ts
+++ b/app/src/command/paletteCore.test.ts
@@ -51,9 +51,25 @@ describe("command palette core", () => {
const events: string[] = [];
const lifecycle = createPaletteFocusLifecycle(() => events.push("restore"));
- lifecycle.restoreAfterCancel();
- lifecycle.restoreAfterCancel();
+ assert.equal(lifecycle.restoreAfterCancel(), true);
+ assert.equal(lifecycle.restoreAfterCancel(), true);
assert.deepEqual(events, ["restore"]);
});
+
+ it("can cancel without restoring focus", () => {
+ const events: string[] = [];
+ const lifecycle = createPaletteFocusLifecycle(() => events.push("restore"));
+
+ assert.equal(lifecycle.restoreAfterCancel(false), true);
+ assert.deepEqual(events, []);
+ });
+
+ it("does not treat command execution as cancellation", () => {
+ const lifecycle = createPaletteFocusLifecycle(() => undefined);
+
+ lifecycle.prepareCommand();
+
+ assert.equal(lifecycle.restoreAfterCancel(false), false);
+ });
});
diff --git a/app/src/command/paletteCore.ts b/app/src/command/paletteCore.ts
index 21fb903a24..6133b95378 100644
--- a/app/src/command/paletteCore.ts
+++ b/app/src/command/paletteCore.ts
@@ -20,10 +20,11 @@ export const createPaletteFocusLifecycle = (restore: () => void) => {
commandSelected = true;
restoreOnce();
},
- restoreAfterCancel() {
- if (!commandSelected) {
+ restoreAfterCancel(shouldRestore = true) {
+ if (!commandSelected && shouldRestore) {
restoreOnce();
}
+ return !commandSelected;
},
};
};
diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.ts
index 5222f47583..4e12ff908a 100644
--- a/app/src/mobile/menu/search.ts
+++ b/app/src/mobile/menu/search.ts
@@ -354,6 +354,7 @@ export const updateSearchResult = (config: Config.IUILayoutTabSearchConfig, elem
};
const initSearchEvent = (app: App, element: Element, config: Config.IUILayoutTabSearchConfig) => {
+ let focusTimeout = 0;
const searchInputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
searchInputElement.value = config.k || "";
searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
@@ -388,7 +389,10 @@ const initSearchEvent = (app: App, element: Element, config: Config.IUILayoutTab
});
if (window.JSAndroid?.showKeyboard || window.JSHarmony?.showKeyboard) {
callMobileAppShowKeyboard();
- setTimeout(() => searchInputElement.focus(), Constants.TIMEOUT_TRANSITION);
+ focusTimeout = window.setTimeout(() => {
+ focusTimeout = 0;
+ searchInputElement.focus();
+ }, Constants.TIMEOUT_TRANSITION);
} else {
searchInputElement.focus();
}
@@ -751,6 +755,7 @@ const initSearchEvent = (app: App, element: Element, config: Config.IUILayoutTab
target = target.parentElement;
}
}, false);
+ return () => clearTimeout(focusTimeout);
};
export const popSearch = (app: App, searchConfig?: Config.IUILayoutTabSearchConfig) => {
@@ -789,6 +794,7 @@ export const popSearch = (app: App, searchConfig?: Config.IUILayoutTabSearchConf
}
});
+ let destroySearchEvent: (() => void) | undefined;
openModel({
title: `<div class="fn__flex">
<span data-menu="true" class="toolbar__icon toolbar__icon--history" data-type="history">
@@ -884,6 +890,8 @@ export const popSearch = (app: App, searchConfig?: Config.IUILayoutTabSearchConf
<div class="fn__loading"><img width="120px" src="/stage/loading-pure.svg"></div>
</div>`,
destroyCallback() {
+ destroySearchEvent?.();
+ activeBlur(true);
cancelSearchRequest(document.getElementById("modelMain"));
},
bindEvent(element) {
@@ -894,7 +902,7 @@ export const popSearch = (app: App, searchConfig?: Config.IUILayoutTabSearchConf
historyElement.addEventListener("click", () => {
toggleSearchHistory(document.querySelector("#model"), config, undefined, element);
});
- initSearchEvent(app, element, config);
+ destroySearchEvent = initSearchEvent(app, element, config);
updateSearchResult(config, element);
}
});
diff --git a/app/src/mobile/util/closePanel.ts b/app/src/mobile/util/closePanel.ts
index d22a4ce334..ef3398ec0b 100644
--- a/app/src/mobile/util/closePanel.ts
+++ b/app/src/mobile/util/closePanel.ts
@@ -38,7 +38,7 @@ export const closePanel = () => {
};
export const closeModel = () => {
- activeBlur();
+ activeBlur(true);
destroyModel();
document.getElementById("model").style.transform = "";
};