Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/11133

Vanessafbd64a0c88b5
diff --git a/app/src/boot/globalEvent/commandPanel.ts b/app/src/boot/globalEvent/commandPanel.ts
index a640126c75..5c3fd70be4 100644
--- a/app/src/boot/globalEvent/commandPanel.ts
+++ b/app/src/boot/globalEvent/commandPanel.ts
@@ -5,18 +5,23 @@ import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {isMobile} from "../../util/functions";
import {Constants} from "../../constants";
import {Editor} from "../../editor";
-/// #if !MOBILE
-import {getActiveTab, getDockByType} from "../../layout/tabUtil";
+/// #if MOBILE
+import {getCurrentEditor} from "../../mobile/editor";
+import {openDock} from "../../mobile/dock/util";
+import {popMenu} from "../../mobile/menu";
+/// #else
+import {closeTabByType, getActiveTab, getDockByType} from "../../layout/tabUtil";
import {Custom} from "../../layout/dock/Custom";
import {getAllModels} from "../../layout/getAll";
import {Files} from "../../layout/dock/Files";
import {Search} from "../../search";
+import {openSetting} from "../../config";
+import {Tab} from "../../layout/Tab";
/// #endif
+import {openHistory} from "../../history/history";
import {addEditorToDatabase, addFilesToDatabase} from "../../protyle/render/av/addToDatabase";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {newDailyNote} from "../../util/mount";
-import {getCurrentEditor} from "../../mobile/editor";
-import {openDock} from "../../mobile/dock/util";
export const commandPanel = (app: App) => {
const range = getSelection().getRangeAt(0);
@@ -43,8 +48,8 @@ export const commandPanel = (app: App) => {
Object.keys(window.siyuan.config.keymap.general).forEach((key) => {
let keys;
/// #if MOBILE
- keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
- "graphView", "globalGraph", "config", "dataHistory"];
+ keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks", "config",
+ "dataHistory"];
/// #else
keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
"graphView", "globalGraph", "closeAll", "closeLeft", "closeOthers", "closeRight", "closeTab",
@@ -155,7 +160,7 @@ const filterList = (inputElement: HTMLInputElement, listElement: Element) => {
export const execByCommand = (options: {
command: string,
- app: App,
+ app?: App,
previousRange?: Range,
protyle?: IProtyle,
fileLiElements?: Element[]
@@ -174,6 +179,9 @@ export const execByCommand = (options: {
case "backlinks":
openDock("backlink");
return;
+ case "config":
+ popMenu();
+ return;
}
/// #else
switch (options.command) {
@@ -184,13 +192,9 @@ export const execByCommand = (options: {
getDockByType("outline").toggleModel("outline");
return;
case "bookmark":
- getDockByType("bookmark").toggleModel("bookmark");
- return;
case "tag":
- getDockByType("tag").toggleModel("tag");
- return;
case "inbox":
- getDockByType("inbox").toggleModel("inbox");
+ getDockByType(options.command).toggleModel(options.command);
return;
case "backlinks":
getDockByType("backlink").toggleModel("backlink");
@@ -201,12 +205,90 @@ export const execByCommand = (options: {
case "globalGraph":
getDockByType("globalGraph").toggleModel("globalGraph");
return;
+ case "config":
+ openSetting(options.app);
+ return;
+ }
+ if (options.command === "closeUnmodified") {
+ const tab = getActiveTab(false);
+ if (tab) {
+ const unmodifiedTabs: Tab[] = [];
+ tab.parent.children.forEach((item: Tab) => {
+ const editor = item.model as Editor;
+ if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
+ unmodifiedTabs.push(item);
+ }
+ });
+ if (unmodifiedTabs.length > 0) {
+ closeTabByType(tab, "other", unmodifiedTabs);
+ }
+ }
+ return;
+ }
+ if (options.command === "closeTab") {
+ const activeTabElement = document.querySelector(".layout__tab--active");
+ if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
+ let type = "";
+ Array.from(activeTabElement.classList).find(item => {
+ if (item.startsWith("sy__")) {
+ type = item.replace("sy__", "");
+ return true;
+ }
+ });
+ if (type) {
+ getDockByType(type)?.toggleModel(type, false, true);
+ }
+ return;
+ }
+ const tab = getActiveTab(false);
+ if (tab) {
+ tab.parent.removeTab(tab.id);
+ }
+ return;
+ }
+ if (options.command === "closeOthers" || options.command === "closeAll") {
+ const tab = getActiveTab(false);
+ if (tab) {
+ closeTabByType(tab, options.command);
+ }
+ return;
+ }
+ if (options.command === "closeLeft" || options.command === "closeRight") {
+ const tab = getActiveTab(false);
+ if (tab) {
+ const leftTabs: Tab[] = [];
+ const rightTabs: Tab[] = [];
+ let midIndex = -1;
+ tab.parent.children.forEach((item: Tab, index: number) => {
+ if (item.id === tab.id) {
+ midIndex = index;
+ }
+ if (midIndex === -1) {
+ leftTabs.push(item);
+ } else if (index > midIndex) {
+ rightTabs.push(item);
+ }
+ });
+ if (options.command === "closeLeft") {
+ if (leftTabs.length > 0) {
+ closeTabByType(tab, "other", leftTabs);
+ }
+ } else {
+ if (rightTabs.length > 0) {
+ closeTabByType(tab, "other", rightTabs);
+ }
+ }
+ }
+ return;
}
/// #endif
switch (options.command) {
case "dailyNote":
newDailyNote(options.app);
return;
+ case "dataHistory":
+ openHistory(options.app);
+ return;
}
const isFileFocus = document.querySelector(".layout__tab--active")?.classList.contains("sy__file");
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index b875fb7138..378624d44b 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -1274,10 +1274,8 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return;
}
- if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
- if (!window.siyuan.config.readonly) {
- openHistory(app);
- }
+ if (matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
+ openHistory(app);
event.preventDefault();
return;
}
@@ -1448,25 +1446,10 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
// close tab
if (matchHotKey(window.siyuan.config.keymap.general.closeTab.custom, event) && !event.repeat) {
+ execByCommand({
+ command: "closeTab"
+ });
event.preventDefault();
- const activeTabElement = document.querySelector(".layout__tab--active");
- if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
- let type = "";
- Array.from(activeTabElement.classList).find(item => {
- if (item.startsWith("sy__")) {
- type = item.replace("sy__", "");
- return true;
- }
- });
- if (type) {
- getDockByType(type)?.toggleModel(type, false, true);
- }
- return;
- }
- const tab = getActiveTab(false);
- if (tab) {
- tab.parent.removeTab(tab.id);
- }
return;
}
@@ -1527,69 +1510,40 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.closeOthers.custom, event) && !event.repeat) {
- const tab = getActiveTab(false);
- if (tab) {
- closeTabByType(tab, "closeOthers");
- }
+ execByCommand({
+ command: "closeOthers"
+ });
event.preventDefault();
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.closeAll.custom, event) && !event.repeat) {
- const tab = getActiveTab(false);
- if (tab) {
- closeTabByType(tab, "closeAll");
- }
+ execByCommand({
+ command: "closeAll"
+ });
event.preventDefault();
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.closeUnmodified.custom, event) && !event.repeat) {
- const tab = getActiveTab(false);
- if (tab) {
- const unmodifiedTabs: Tab[] = [];
- tab.parent.children.forEach((item: Tab) => {
- const editor = item.model as Editor;
- if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
- unmodifiedTabs.push(item);
- }
- });
- if (unmodifiedTabs.length > 0) {
- closeTabByType(tab, "other", unmodifiedTabs);
- }
- }
+ execByCommand({
+ command: "closeUnmodified"
+ });
event.preventDefault();
return;
}
- if ((matchHotKey(window.siyuan.config.keymap.general.closeLeft.custom, event) || matchHotKey(window.siyuan.config.keymap.general.closeRight.custom, event)) &&
- !event.repeat) {
- const tab = getActiveTab(false);
- if (tab) {
- const leftTabs: Tab[] = [];
- const rightTabs: Tab[] = [];
- let midIndex = -1;
- tab.parent.children.forEach((item: Tab, index: number) => {
- if (item.id === tab.id) {
- midIndex = index;
- }
- if (midIndex === -1) {
- leftTabs.push(item);
- } else if (index > midIndex) {
- rightTabs.push(item);
- }
- });
- if (matchHotKey(window.siyuan.config.keymap.general.closeLeft.custom, event)) {
- if (leftTabs.length > 0) {
- closeTabByType(tab, "other", leftTabs);
- }
- } else {
- if (rightTabs.length > 0) {
- closeTabByType(tab, "other", rightTabs);
- }
- }
- }
+ if (matchHotKey(window.siyuan.config.keymap.general.closeLeft.custom, event) && !event.repeat) {
+ execByCommand({
+ command: "closeLeft"
+ });
+ event.preventDefault();
+ return;
+ }
+ if (matchHotKey(window.siyuan.config.keymap.general.closeRight.custom, event) && !event.repeat) {
+ execByCommand({
+ command: "closeRight"
+ });
event.preventDefault();
return;
}
-
if ((
matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event) ||
matchHotKey(window.siyuan.config.keymap.general.splitMoveR.custom, event) ||