Skip to content

Commit ec6e7a0

Browse files
committed
🎨 #11205 & #15824
1 parent d9e0c56 commit ec6e7a0

File tree

9 files changed

+62
-57
lines changed

9 files changed

+62
-57
lines changed

app/src/boot/globalEvent/command/global.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {openCard} from "../../../card/openCard";
4040
import {syncGuide} from "../../../sync/syncGuide";
4141
import {Wnd} from "../../../layout/Wnd";
4242
import {unsplitWnd} from "../../../menus/tab";
43+
import {openFileById} from "../../../editor/util";
4344

4445
export const globalCommand = (command: string, app: App) => {
4546
/// #if MOBILE
@@ -148,6 +149,15 @@ export const globalCommand = (command: string, app: App) => {
148149
case "recentDocs":
149150
openRecentDocs();
150151
return true;
152+
case "recentClosed":
153+
if (window.siyuan.closedTabs.length > 0) {
154+
openFileById({
155+
app,
156+
id: window.siyuan.closedTabs.pop(),
157+
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
158+
});
159+
}
160+
return true;
151161
case "toggleDock":
152162
toggleDockBar(document.querySelector("#barDock use"));
153163
return true;

app/src/boot/globalEvent/command/panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const commandPanel = (app: App) => {
6666
"goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
6767
"mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search", "selectOpen1", "syncNow",
6868
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "tabToWindow", "stickSearch", "toggleDock", "unsplitAll",
69-
"unsplit"];
69+
"unsplit", "recentClosed"];
7070
/// #if !BROWSER
7171
keys.push("toggleWin");
7272
/// #endif

app/src/boot/globalEvent/keydown.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,15 +1532,10 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
15321532
return;
15331533
}
15341534

1535-
if (matchHotKey("⇧⌘T", event)) {
1536-
if ((window as any).siyuan.closedTabs && (window as any).siyuan.closedTabs.length > 0) {
1537-
const closedTab = (window as any).siyuan.closedTabs.pop();
1538-
openFileById({
1539-
app,
1540-
id: closedTab.id,
1541-
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
1542-
});
1543-
}
1535+
if (matchHotKey(window.siyuan.config.keymap.general.recentClosed.custom, event)) {
1536+
execByCommand({
1537+
command: "closeTab"
1538+
});
15441539
event.preventDefault();
15451540
return;
15461541
}

app/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ export abstract class Constants {
453453
goToTabPrev: {default: "⇧⌘[", custom: "⇧⌘["},
454454
goToEditTabNext: {default: "⌃⇥", custom: "⌃⇥"},
455455
goToEditTabPrev: {default: "⌃⇧⇥", custom: "⌃⇧⇥"},
456+
recentClosed: {default: "⇧⌘T", custom: "⇧⌘T"},
456457
move: {default: "", custom: ""},
457458
selectOpen1: {default: "", custom: ""},
458459
toggleDock: {default: "", custom: ""},

app/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class App {
5656
layout: {},
5757
dialogs: [],
5858
blockPanels: [],
59+
closedTabs: [],
5960
ctrlIsPressed: false,
6061
altIsPressed: false,
6162
ws: new Model({

app/src/layout/Wnd.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ export class Wnd {
558558
if (update) {
559559
// 更新文档浏览时间
560560
fetchPost("/api/storage/updateRecentDocViewTime", {rootID: currentTab.model.editor.protyle.block.rootID});
561-
561+
562562
updatePanelByEditor({
563563
protyle: currentTab.model.editor.protyle,
564564
focus: true,
@@ -636,12 +636,12 @@ export class Wnd {
636636
if (tab.callback) {
637637
tab.callback(tab);
638638
}
639-
639+
640640
// 当文档第一次加载到页签时更新 openAt 时间
641641
if (tab.model instanceof Editor && tab.model.editor?.protyle?.block?.rootID) {
642642
fetchPost("/api/storage/updateRecentDocOpenTime", {rootID: tab.model.editor.protyle.block.rootID});
643643
}
644-
644+
645645
// 移除 centerLayout 中的 empty
646646
if (this.parent.type === "center" && this.children.length === 2 && !this.children[0].headElement) {
647647
this.removeTab(this.children[0].id);
@@ -793,12 +793,7 @@ export class Wnd {
793793
saveScroll(item.model.editor.protyle);
794794
// 更新文档关闭时间
795795
fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: item.model.editor.protyle.block.rootID});
796-
if (!(window as any).siyuan.closedTabs) {
797-
(window as any).siyuan.closedTabs = [];
798-
}
799-
(window as any).siyuan.closedTabs.push({
800-
id: item.model.editor.protyle.block.rootID
801-
});
796+
window.siyuan.closedTabs.push(item.model.editor.protyle.block.rootID);
802797
}
803798
if (this.children.length === 1) {
804799
this.destroyModel(this.children[0].model);

app/src/types/config.d.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,29 +1000,35 @@ declare namespace Config {
10001000
* SiYuan general shortcut keys
10011001
*/
10021002
export interface IKeymapGeneral extends IKeys {
1003-
addToDatabase: IKey;
1004-
backlinks: IKey;
1005-
bookmark: IKey;
1006-
closeAll: IKey;
1007-
closeLeft: IKey;
1008-
closeOthers: IKey;
1009-
closeRight: IKey;
1010-
closeTab: IKey;
1011-
closeUnmodified: IKey;
1003+
mainMenu: IKey;
10121004
commandPanel: IKey;
1013-
config: IKey;
1014-
dailyNote: IKey;
1015-
dataHistory: IKey;
10161005
editReadonly: IKey;
1017-
enter: IKey;
1006+
syncNow: IKey;
10181007
enterBack: IKey;
1008+
enter: IKey;
1009+
goForward: IKey;
1010+
goBack: IKey;
1011+
newFile: IKey;
1012+
search: IKey;
1013+
globalSearch: IKey;
1014+
stickSearch: IKey;
1015+
replace: IKey;
1016+
closeTab: IKey;
10191017
fileTree: IKey;
1018+
outline: IKey;
1019+
bookmark: IKey;
1020+
tag: IKey;
1021+
dailyNote: IKey;
1022+
inbox: IKey;
1023+
backlinks: IKey;
1024+
graphView: IKey;
10201025
globalGraph: IKey;
1021-
globalSearch: IKey;
1022-
goBack: IKey;
1023-
goForward: IKey;
1024-
goToEditTabNext: IKey;
1025-
goToEditTabPrev: IKey;
1026+
riffCard: IKey;
1027+
config: IKey;
1028+
dataHistory: IKey;
1029+
toggleWin: IKey;
1030+
lockScreen: IKey;
1031+
recentDocs: IKey;
10261032
goToTab1: IKey;
10271033
goToTab2: IKey;
10281034
goToTab3: IKey;
@@ -1034,28 +1040,25 @@ declare namespace Config {
10341040
goToTab9: IKey;
10351041
goToTabNext: IKey;
10361042
goToTabPrev: IKey;
1037-
graphView: IKey;
1038-
inbox: IKey;
1039-
lockScreen: IKey;
1040-
mainMenu: IKey;
1043+
goToEditTabNext: IKey;
1044+
goToEditTabPrev: IKey;
1045+
recentClosed: IKey;
10411046
move: IKey;
1042-
newFile: IKey;
1043-
outline: IKey;
1044-
recentDocs: IKey;
1045-
replace: IKey;
1046-
riffCard: IKey;
1047-
search: IKey;
10481047
selectOpen1: IKey;
1048+
toggleDock: IKey;
10491049
splitLR: IKey;
1050-
splitMoveB: IKey;
10511050
splitMoveR: IKey;
10521051
splitTB: IKey;
1053-
stickSearch: IKey;
1054-
syncNow: IKey;
1052+
splitMoveB: IKey;
1053+
closeOthers: IKey;
1054+
closeAll: IKey;
1055+
closeUnmodified: IKey;
1056+
closeLeft: IKey;
1057+
closeRight: IKey;
10551058
tabToWindow: IKey;
1056-
tag: IKey;
1057-
toggleDock: IKey;
1058-
toggleWin: IKey;
1059+
addToDatabase: IKey;
1060+
unsplit: IKey;
1061+
unsplitAll: IKey;
10591062
}
10601063

10611064
/**

app/src/types/index.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ interface Window {
216216
encode(options: string): string,
217217
};
218218
pdfjsLib: any;
219-
220-
dataLayer: any[];
221-
222-
siyuan: ISiyuan;
223219
webkit: {
224220
messageHandlers: {
225221
openLink: { postMessage: (url: string) => void }
@@ -233,6 +229,8 @@ interface Window {
233229
toCanvas: (element: Element) => Promise<HTMLCanvasElement>
234230
toBlob: (element: Element) => Promise<Blob>
235231
};
232+
233+
siyuan: ISiyuan;
236234
JSAndroid: {
237235
returnDesktop(): void
238236
openExternal(url: string): void
@@ -462,6 +460,7 @@ interface ISiyuan {
462460
storage?: {
463461
[key: string]: any
464462
},
463+
closedTabs: string[]
465464
transactions?: {
466465
protyle: IProtyle,
467466
doOperations: IOperation[],

app/src/window/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class App {
4343
layout: {},
4444
dialogs: [],
4545
blockPanels: [],
46+
closedTabs: [],
4647
ctrlIsPressed: false,
4748
altIsPressed: false,
4849
ws: new Model({

0 commit comments

Comments
 (0)