diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.ts index e47cfe57c..b9eabb563 100644 --- a/app/src/boot/globalEvent/command/global.ts +++ b/app/src/boot/globalEvent/command/global.ts @@ -40,6 +40,7 @@ import {openCard} from "../../../card/openCard"; import {syncGuide} from "../../../sync/syncGuide"; import {Wnd} from "../../../layout/Wnd"; import {unsplitWnd} from "../../../menus/tab"; +import {openFileById} from "../../../editor/util"; export const globalCommand = (command: string, app: App) => { /// #if MOBILE @@ -148,6 +149,15 @@ export const globalCommand = (command: string, app: App) => { case "recentDocs": openRecentDocs(); return true; + case "recentClosed": + if (window.siyuan.closedTabs.length > 0) { + openFileById({ + app, + id: window.siyuan.closedTabs.pop(), + action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL] + }); + } + return true; case "toggleDock": toggleDockBar(document.querySelector("#barDock use")); return true; diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.ts index 2138892f4..95c6fcad0 100644 --- a/app/src/boot/globalEvent/command/panel.ts +++ b/app/src/boot/globalEvent/command/panel.ts @@ -66,7 +66,7 @@ export const commandPanel = (app: App) => { "goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen", "mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search", "selectOpen1", "syncNow", "splitLR", "splitMoveB", "splitMoveR", "splitTB", "tabToWindow", "stickSearch", "toggleDock", "unsplitAll", - "unsplit"]; + "unsplit", "recentClosed"]; /// #if !BROWSER keys.push("toggleWin"); /// #endif diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 35143f8e0..bd3845636 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -1532,15 +1532,10 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => { return; } - if (matchHotKey("⇧⌘T", event)) { - if ((window as any).siyuan.closedTabs && (window as any).siyuan.closedTabs.length > 0) { - const closedTab = (window as any).siyuan.closedTabs.pop(); - openFileById({ - app, - id: closedTab.id, - action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL] - }); - } + if (matchHotKey(window.siyuan.config.keymap.general.recentClosed.custom, event)) { + execByCommand({ + command: "closeTab" + }); event.preventDefault(); return; } diff --git a/app/src/constants.ts b/app/src/constants.ts index b8c0e9c69..048c7c92f 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -453,6 +453,7 @@ export abstract class Constants { goToTabPrev: {default: "⇧⌘[", custom: "⇧⌘["}, goToEditTabNext: {default: "⌃⇥", custom: "⌃⇥"}, goToEditTabPrev: {default: "⌃⇧⇥", custom: "⌃⇧⇥"}, + recentClosed: {default: "⇧⌘T", custom: "⇧⌘T"}, move: {default: "", custom: ""}, selectOpen1: {default: "", custom: ""}, toggleDock: {default: "", custom: ""}, diff --git a/app/src/index.ts b/app/src/index.ts index e932fd8ba..847493c7c 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -56,6 +56,7 @@ export class App { layout: {}, dialogs: [], blockPanels: [], + closedTabs: [], ctrlIsPressed: false, altIsPressed: false, ws: new Model({ diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index ddb9d7d88..32c75fcfc 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -558,7 +558,7 @@ export class Wnd { if (update) { // 更新文档浏览时间 fetchPost("/api/storage/updateRecentDocViewTime", {rootID: currentTab.model.editor.protyle.block.rootID}); - + updatePanelByEditor({ protyle: currentTab.model.editor.protyle, focus: true, @@ -636,12 +636,12 @@ export class Wnd { if (tab.callback) { tab.callback(tab); } - + // 当文档第一次加载到页签时更新 openAt 时间 if (tab.model instanceof Editor && tab.model.editor?.protyle?.block?.rootID) { fetchPost("/api/storage/updateRecentDocOpenTime", {rootID: tab.model.editor.protyle.block.rootID}); } - + // 移除 centerLayout 中的 empty if (this.parent.type === "center" && this.children.length === 2 && !this.children[0].headElement) { this.removeTab(this.children[0].id); @@ -793,12 +793,7 @@ export class Wnd { saveScroll(item.model.editor.protyle); // 更新文档关闭时间 fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: item.model.editor.protyle.block.rootID}); - if (!(window as any).siyuan.closedTabs) { - (window as any).siyuan.closedTabs = []; - } - (window as any).siyuan.closedTabs.push({ - id: item.model.editor.protyle.block.rootID - }); + window.siyuan.closedTabs.push(item.model.editor.protyle.block.rootID); } if (this.children.length === 1) { this.destroyModel(this.children[0].model); diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts index 5cfbdddd0..d071554b4 100644 --- a/app/src/types/config.d.ts +++ b/app/src/types/config.d.ts @@ -1000,29 +1000,35 @@ declare namespace Config { * SiYuan general shortcut keys */ export interface IKeymapGeneral extends IKeys { - addToDatabase: IKey; - backlinks: IKey; - bookmark: IKey; - closeAll: IKey; - closeLeft: IKey; - closeOthers: IKey; - closeRight: IKey; - closeTab: IKey; - closeUnmodified: IKey; + mainMenu: IKey; commandPanel: IKey; - config: IKey; - dailyNote: IKey; - dataHistory: IKey; editReadonly: IKey; - enter: IKey; + syncNow: IKey; enterBack: IKey; - fileTree: IKey; - globalGraph: IKey; - globalSearch: IKey; - goBack: IKey; + enter: IKey; goForward: IKey; - goToEditTabNext: IKey; - goToEditTabPrev: IKey; + goBack: IKey; + newFile: IKey; + search: IKey; + globalSearch: IKey; + stickSearch: IKey; + replace: IKey; + closeTab: IKey; + fileTree: IKey; + outline: IKey; + bookmark: IKey; + tag: IKey; + dailyNote: IKey; + inbox: IKey; + backlinks: IKey; + graphView: IKey; + globalGraph: IKey; + riffCard: IKey; + config: IKey; + dataHistory: IKey; + toggleWin: IKey; + lockScreen: IKey; + recentDocs: IKey; goToTab1: IKey; goToTab2: IKey; goToTab3: IKey; @@ -1034,28 +1040,25 @@ declare namespace Config { goToTab9: IKey; goToTabNext: IKey; goToTabPrev: IKey; - graphView: IKey; - inbox: IKey; - lockScreen: IKey; - mainMenu: IKey; + goToEditTabNext: IKey; + goToEditTabPrev: IKey; + recentClosed: IKey; move: IKey; - newFile: IKey; - outline: IKey; - recentDocs: IKey; - replace: IKey; - riffCard: IKey; - search: IKey; selectOpen1: IKey; + toggleDock: IKey; splitLR: IKey; - splitMoveB: IKey; splitMoveR: IKey; splitTB: IKey; - stickSearch: IKey; - syncNow: IKey; + splitMoveB: IKey; + closeOthers: IKey; + closeAll: IKey; + closeUnmodified: IKey; + closeLeft: IKey; + closeRight: IKey; tabToWindow: IKey; - tag: IKey; - toggleDock: IKey; - toggleWin: IKey; + addToDatabase: IKey; + unsplit: IKey; + unsplitAll: IKey; } /** diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index e38343147..68de08f8a 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -216,10 +216,6 @@ interface Window { encode(options: string): string, }; pdfjsLib: any; - - dataLayer: any[]; - - siyuan: ISiyuan; webkit: { messageHandlers: { openLink: { postMessage: (url: string) => void } @@ -233,6 +229,8 @@ interface Window { toCanvas: (element: Element) => Promise toBlob: (element: Element) => Promise }; + + siyuan: ISiyuan; JSAndroid: { returnDesktop(): void openExternal(url: string): void @@ -462,6 +460,7 @@ interface ISiyuan { storage?: { [key: string]: any }, + closedTabs: string[] transactions?: { protyle: IProtyle, doOperations: IOperation[], diff --git a/app/src/window/index.ts b/app/src/window/index.ts index bb847833c..eab152d41 100644 --- a/app/src/window/index.ts +++ b/app/src/window/index.ts @@ -43,6 +43,7 @@ class App { layout: {}, dialogs: [], blockPanels: [], + closedTabs: [], ctrlIsPressed: false, altIsPressed: false, ws: new Model({