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/18728

Vanessa90fa50119b3f
diff --git a/app/src/config/tabs/keymapUi.ts b/app/src/config/tabs/keymapUi.ts
index 5a0b56976b..f0dbc3e44e 100644
--- a/app/src/config/tabs/keymapUi.ts
+++ b/app/src/config/tabs/keymapUi.ts
@@ -13,7 +13,7 @@ import {sendGlobalShortcut, sendUnregisterGlobalShortcut} from "../../boot/globa
import {normalizeSearchText} from "../search/normalize";
import {genButtonRowHtml, genConfigGroup} from "../render/render";
import type {Plugin} from "../../plugin";
-import {isDisallowedTextInputHotkey} from "../../util/hotKeyPolicy";
+import {isDisallowedTextInputHotkey, isReservedKeymap} from "../../util/hotKeyPolicy";
const keymapToolbarSearchStrings = (): string[] => [
window.siyuan.languages.keymapTip,
window.siyuan.languages.keymapTip2,
@@ -444,7 +444,7 @@ const bindKeymapList = (root: HTMLElement) => {
hasConflict = true;
}
if (
- !hasConflict && (isDisallowedTextInputHotkey(keymapStr) || RESERVED_KEYMAPS.includes(keymapStr) ||
+ !hasConflict && (isDisallowedTextInputHotkey(keymapStr) || isReservedKeymap(keymapStr, keys) ||
!matchHotKey(keymapStr, event) ||
(isMac() && keys[0] === "general" && ["goToEditTabNext", "goToEditTabPrev"].includes(keys[1]) && keymapStr.includes("⌘")))
) {
@@ -507,9 +507,6 @@ const bindKeymapList = (root: HTMLElement) => {
});
};
-const RESERVED_KEYMAPS = ["⌘A", "⌘X", "⌘C", "⌘V", "⌘-", "⌘=", "⌘0", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥",
- "⌃D", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦", "Escape"];
-
const getKeymapString = (event: KeyboardEvent) => {
const mac = isMac();
let keymapStr = "";
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 698787ea57..0bae9e132b 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -455,7 +455,7 @@ export abstract class Constants {
// 冲突不使用 "⌘S/Q"
// "⌘", "⇧", "⌥", "⌃"
// "⌘A", "⌘X", "⌘C", "⌘V", "⌘-", "⌘=", "⌘0", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⌃D", "⇧⌘→", "⇧⌘←",
- // "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦", "Escape" 不可自定义
+ // "⌘Home", "⌘End", "⇧↩", "PageUp", "PageDown", "⌫", "⌦", "Escape" 不可自定义
// "⌥↩" 写死,但可自定义
public static readonly SIYUAN_KEYMAP: Config.IKeymap = {
general: {
@@ -630,7 +630,7 @@ export abstract class Constants {
list: {
indent: {default: "⇥", custom: "⇥"},
outdent: {default: "⇧⇥", custom: "⇧⇥"},
- checkToggle: {default: "⌘↩", custom: "⌘↩"},
+ checkToggle: {default: "⇧⌘L", custom: "⇧⌘L"},
prependListItem: {default: "", custom: ""},
appendListItem: {default: "", custom: ""},
},
diff --git a/app/src/util/hotKeyPolicy.test.ts b/app/src/util/hotKeyPolicy.test.ts
index 9cb3966ecb..da0902c553 100644
--- a/app/src/util/hotKeyPolicy.test.ts
+++ b/app/src/util/hotKeyPolicy.test.ts
@@ -4,6 +4,7 @@ import {
clearDisallowedKeymapItems,
clearDisallowedTextInputHotkey,
isDisallowedTextInputHotkey,
+ isReservedKeymap,
normalizePluginHotkey,
} from "./hotKeyPolicy";
@@ -32,6 +33,13 @@ describe("text input hotkey policy", () => {
});
});
+ it("allows Enter only for the agent send shortcut", () => {
+ assert.equal(isReservedKeymap("↩", ["general", "agentSend"]), false);
+ assert.equal(isReservedKeymap("↩", ["general", "agentChat"]), true);
+ assert.equal(isReservedKeymap("↩", ["editor", "general", "insertAfter"]), true);
+ assert.equal(isReservedKeymap("⇧↩", ["general", "agentSend"]), true);
+ });
+
it("clears only disallowed text input hotkeys", () => {
assert.equal(clearDisallowedTextInputHotkey("⇧S"), "");
assert.equal(clearDisallowedTextInputHotkey("⇧F1"), "⇧F1");
diff --git a/app/src/util/hotKeyPolicy.ts b/app/src/util/hotKeyPolicy.ts
index fd1629247c..bbe47a80db 100644
--- a/app/src/util/hotKeyPolicy.ts
+++ b/app/src/util/hotKeyPolicy.ts
@@ -1,5 +1,10 @@
const MODIFIER_KEYS = "⌃⌥⇧⌘";
const NON_CHARACTER_KEYS = new Set(["←", "↑", "→", "↓", "⇥", "⌫", "⌦", "↩"]);
+const RESERVED_KEYMAPS = new Set(["⌘A", "⌘X", "⌘C", "⌘V", "⌘-", "⌘=", "⌘0", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥",
+ "⌃D", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦", "Escape"]);
+
+export const isReservedKeymap = (hotkey: string, keyPath: string[]) =>
+ RESERVED_KEYMAPS.has(hotkey) && !(hotkey === "↩" && keyPath[0] === "general" && keyPath[1] === "agentSend");
export const isDisallowedTextInputHotkey = (hotkey: string) => {
let mainKeyIndex = 0;