diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.ts index 0ffef3b53..a98bea2f3 100644 --- a/app/src/boot/globalEvent/command/panel.ts +++ b/app/src/boot/globalEvent/command/panel.ts @@ -23,6 +23,7 @@ import {globalCommand} from "./global"; import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath, pathPosix} from "../../../util/pathName"; import {hintMoveBlock} from "../../../protyle/hint/extend"; import {fetchSyncPost} from "../../../util/fetch"; +import {focusByRange} from "../../../protyle/util/selection"; export const commandPanel = (app: App) => { const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined; @@ -41,7 +42,12 @@ export const commandPanel = (app: App) => { ${window.siyuan.languages.enterKey}/${window.siyuan.languages.click} ${window.siyuan.languages.confirm} Esc ${window.siyuan.languages.close} -` +`, + destroyCallback() { + if (range) { + focusByRange(range); + } + }, }); dialog.element.setAttribute("data-key", Constants.DIALOG_COMMANDPANEL); const listElement = dialog.element.querySelector("#commands"); diff --git a/app/src/config/index.ts b/app/src/config/index.ts index 0f372ab87..84c82e367 100644 --- a/app/src/config/index.ts +++ b/app/src/config/index.ts @@ -20,6 +20,7 @@ import {publish} from "./publish"; import {App} from "../index"; import {isHuawei, isInHarmony} from "../protyle/util/compatibility"; import {Constants} from "../constants"; +import {focusByRange} from "../protyle/util/selection"; /// #endif export const genItemPanel = (type: string, containerElement: Element, app: App) => { @@ -107,6 +108,10 @@ export const openSetting = (app: App) => { if (exitDialog) { return exitDialog; } + let range: Range; + if (getSelection().rangeCount > 0) { + range = getSelection().getRangeAt(0); + } const dialog = new Dialog({ content: `
`, width: "90vw", height: "90vh", + destroyCallback() { + if (range) { + focusByRange(range); + } + }, }); dialog.element.setAttribute("data-key", Constants.DIALOG_SETTING);