An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Handle iOS Option shortcuts with Chinese input https://github.com/siyuan-note/siyuan/issues/20006
Danield58593fdde01
diff --git a/app/src/protyle/util/hotKey.test.ts b/app/src/protyle/util/hotKey.test.tsindex 074b9d9a96..c1b90e01fd 100644--- a/app/src/protyle/util/hotKey.test.ts+++ b/app/src/protyle/util/hotKey.test.ts@@ -13,7 +13,7 @@ const fixture = (ios = true, mac = true) => {const exports: any = {};const dependencies: Record<string, object> = {"../../util/keymapBindings": keymapBindings,- "../../constants": {Constants: {KEYCODELIST: {70: "F", 80: "P"}}},+ "../../constants": {Constants: {KEYCODELIST: {67: "C", 70: "F", 76: "L", 80: "P", 82: "R"}}},"./compatibility": {isInIOS: () => ios,isMac: () => mac,@@ -53,6 +53,30 @@ test("iOS Command fallback preserves composition and modifier boundaries", () =>assert.equal(match("⌥⌘P", event("p", {altKey: true})), true);});+test("iOS Chinese input matches Option alignment shortcuts before composition starts", () => {+ const match = fixture();+ for (const key of ["c", "l", "r", "C", "L", "R"]) {+ const input = event(key, {metaKey: false, altKey: true});+ assert.equal(match(`⌥${key.toUpperCase()}`, input), true);+ assert.equal(match(key.toLowerCase() === "c" ? "⌥L" : "⌥C", input), false);+ assert.equal(input.keyCode, 229);+ }+ assert.equal(match("⌥⇧C", event("C", {metaKey: false, altKey: true, shiftKey: true})), true);+});++test("iOS Option fallback preserves composition, text input, and modifier boundaries", () => {+ const match = fixture();+ const input = event("c", {metaKey: false, altKey: true});+ for (const overrides of [{isComposing: true}, {altKey: false}, {metaKey: true}, {ctrlKey: true},+ {shiftKey: true}, {key: "Process"}, {key: "Unidentified"}, {key: "Dead"}, {key: "ç"}, {key: ""}]) {+ assert.equal(match("⌥C", {...input, ...overrides}), false, JSON.stringify(overrides));+ }+ assert.equal(match("C", event("c", {metaKey: false})), false);+ assert.equal(match("⇧C", event("C", {metaKey: false, shiftKey: true})), false);+ assert.equal(match("⌥⌘C", {...input, metaKey: true}), true);+ assert.equal(match("⌃⌥C", {...input, ctrlKey: true}), true);+});+test("fallback follows custom and multiple bindings, including explicit unbinding", () => {const match = fixture();const binding = {default: "⌘F", custom: "⌘F"};@@ -65,13 +89,28 @@ test("fallback follows custom and multiple bindings, including explicit unbindinassert.equal(match(binding, event("k")), false);});+test("Option fallback follows custom bindings and explicit unbinding", () => {+ const match = fixture();+ const binding = {default: "⌥C", custom: "⌥C"};+ const input = (key: string, shiftKey = false) => event(key, {metaKey: false, altKey: true, shiftKey});+ keymapBindings.setKeymapBindings(binding, ["⌥L", "⌥⇧R"]);+ assert.equal(match(binding, input("c")), false);+ assert.equal(match(binding, input("l")), true);+ assert.equal(match(binding, input("r", true)), true);+ keymapBindings.setKeymapBindings(binding, []);+ assert.equal(match(binding, input("l")), false);+ assert.equal(match(binding, input("r", true)), false);+});+test("ordinary key codes and non-iOS platform matching remain unchanged", () => {for (const ios of [false, true]) {const match = fixture(ios);assert.equal(match("⌘F", event("f", {keyCode: 70})), true);assert.equal(match("⌘P", event("p", {keyCode: 80})), true);+ assert.equal(match("⌥C", event("ç", {keyCode: 67, metaKey: false, altKey: true})), true);}assert.equal(fixture(false)("⌘F", event("f")), false);+ assert.equal(fixture(false)("⌥C", event("c", {metaKey: false, altKey: true})), false);const windows = fixture(false, false);assert.equal(windows("⌘F", event("f", {keyCode: 70, metaKey: false, ctrlKey: true})), true);assert.equal(windows("⌘F", event("f", {metaKey: false, ctrlKey: true})), false);diff --git a/app/src/protyle/util/hotKey.ts b/app/src/protyle/util/hotKey.tsindex 762c4cdc1c..a6ef11a131 100644--- a/app/src/protyle/util/hotKey.ts+++ b/app/src/protyle/util/hotKey.ts@@ -59,8 +59,8 @@ export const matchHotKey = (hotKey: string | IShortcutKeymap, event: KeyboardEvereturn false;}- // iOS 中文输入法可能将未组词的 Command 字母键标记为 229,此时按实际字母匹配。- const eventKey = event.keyCode === 229 && event.metaKey && !event.isComposing &&+ // iOS 中文输入法可能将未组词的 Command 或 Option 字母键标记为 229,此时按实际字母匹配。+ const eventKey = event.keyCode === 229 && (event.metaKey || event.altKey) && !event.isComposing &&/^[a-z]$/i.test(event.key) && isInIOS() ? event.key.toUpperCase() : Constants.KEYCODELIST[event.keyCode];// []