Skip to content

Commit 4bd2aca

Browse files
committed
还原:修改停靠栏快捷键设置之后不能立即生效 siyuan-note#17675 (comment)
1 parent 4bb8ea7 commit 4bd2aca

5 files changed

Lines changed: 38 additions & 54 deletions

File tree

app/src/config/tabs/keymapUi.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -653,25 +653,13 @@ const setKeymapFromDom = (root: HTMLElement) => {
653653
const newHotkey = item.getAttribute("data-value");
654654
if (keys[0] === "general") {
655655
data[keys[0]][keys[1]].custom = newHotkey;
656-
// 更新原生 dock 按钮 tooltip
657-
document.querySelectorAll(`[data-hotkeylangid="${keys[1]}"]`).forEach(el => {
658-
const title = el.getAttribute("data-title") || "";
659-
const hotkeyTip = newHotkey ? updateHotkeyTip(newHotkey) : "";
660-
el.setAttribute("aria-label", `<span style='white-space:pre'>${title} ${hotkeyTip}${window.siyuan.languages.dockTip}</span>`);
661-
});
662656
} else if (keys[0] === "editor" && isEditorKeymapSegment(keys[1])) {
663657
data.editor[keys[1]][keys[2]].custom = newHotkey;
664658
} else if (keys[0] === "plugin") {
665659
data.plugin[keys[1]][keys[2]].custom = newHotkey;
666660
const plugin = window.siyuan.ws.app.plugins.find((item) => item.name === keys[1]);
667661
const command = plugin?.commands.find((item) => item.langKey === keys[2]);
668662
if (!command) {
669-
// 更新插件 dock 按钮 tooltip
670-
document.querySelectorAll(`.dock__item[data-type="${keys[2]}"]`).forEach(el => {
671-
const title = el.getAttribute("data-title") || "";
672-
const hotkeyTip = newHotkey ? updateHotkeyTip(newHotkey) : "";
673-
el.setAttribute("aria-label", `<span style='white-space:pre'>${title} ${hotkeyTip}${window.siyuan.languages.dockTip}</span>`);
674-
});
675663
return;
676664
}
677665
/// #if !BROWSER

app/src/layout/dock/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ export class Dock {
890890
} else if (item.type === "tags") {
891891
item.icon = "iconTag";
892892
}
893-
html += `<span data-height="${item.size.height}" data-width="${item.size.width}" data-type="${item.type}" data-index="${index}" data-hotkeylangid="${item.hotkeyLangId || ""}" data-title="${item.title}" class="dock__item${item.show ? " dock__item--active" : ""} ariaLabel" aria-label="<span style='white-space:pre'>${item.title} ${item.hotkey ? updateHotkeyTip(item.hotkey) : ""}${window.siyuan.languages.dockTip}</span>">
893+
html += `<span data-height="${item.size.height}" data-width="${item.size.width}" data-type="${item.type}" data-index="${index}" data-hotkey="${item.hotkey || ""}" data-hotkeylangid="${item.hotkeyLangId || ""}" data-title="${item.title}" class="dock__item${item.show ? " dock__item--active" : ""} ariaLabel" aria-label="<span style='white-space:pre'>${item.title} ${item.hotkey ? updateHotkeyTip(item.hotkey) : ""}${window.siyuan.languages.dockTip}</span>">
894894
<svg><use xlink:href="#${item.icon}"></use></svg>
895895
</span>`;
896896
this.data[item.type] = true;

app/src/layout/getAll.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,20 @@ export const getAllTabs = (type?: TTab | string) => {
188188
export const getAllDocks = () => {
189189
const docks: Config.IUILayoutDockTab[] = [];
190190
/// #if !MOBILE
191-
const collectDock = (dock: Config.IUILayoutDockTab) => {
192-
let hotkey = dock.hotkey;
193-
if (dock.hotkeyLangId) {
194-
// 原生 dock 快捷键
195-
hotkey = window.siyuan.config.keymap.general[dock.hotkeyLangId]?.custom ?? dock.hotkey;
196-
} else {
197-
// 插件 dock 快捷键
198-
for (const plugin of window.siyuan.ws.app.plugins) {
199-
const keymap = window.siyuan.config.keymap.plugin[plugin.name]?.[dock.type];
200-
if (keymap) {
201-
hotkey = keymap.custom;
202-
break;
203-
}
204-
}
205-
}
206-
docks.push({...dock, hotkey});
207-
};
208191
window.siyuan.config.uiLayout.left.data.forEach((item) => {
209-
item.forEach(collectDock);
192+
item.forEach((dock) => {
193+
docks.push(dock);
194+
});
210195
});
211196
window.siyuan.config.uiLayout.right.data.forEach((item) => {
212-
item.forEach(collectDock);
197+
item.forEach((dock) => {
198+
docks.push(dock);
199+
});
213200
});
214201
window.siyuan.config.uiLayout.bottom.data.forEach((item) => {
215-
item.forEach(collectDock);
202+
item.forEach((dock) => {
203+
docks.push(dock);
204+
});
216205
});
217206
/// #endif
218207
return docks;

app/src/layout/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const dockToJSON = (dock: Dock) => {
9393
title: item.getAttribute("data-title"),
9494
show: item.classList.contains("dock__item--active"),
9595
icon: item.querySelector("use").getAttribute("xlink:href").substring(1),
96+
hotkey: item.getAttribute("data-hotkey") || "",
9697
hotkeyLangId: item.getAttribute("data-hotkeylangid") || ""
9798
});
9899
});

app/src/protyle/util/hotKey.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,14 @@ export const matchAuxiliaryHotKey = (hotKey: string, event: KeyboardEvent) => {
4242
return true;
4343
};
4444

45-
/** 将快捷键字符串拆分为修饰键与主键,例如 ⌥F10 → ["⌥", "F10"] */
46-
const parseHotKeyTokens = (hotKey: string): string[] => {
47-
const modifiers: string[] = [];
48-
let i = 0;
49-
while (i < hotKey.length && "⌃⌥⇧⌘".includes(hotKey[i])) {
50-
modifiers.push(hotKey[i]);
51-
i++;
52-
}
53-
const rest = hotKey.slice(i);
54-
if (!rest) {
55-
return modifiers;
56-
}
57-
for (const key of ["PageUp", "PageDown", "Home", "End"]) {
58-
if (rest === key) {
59-
return [...modifiers, key];
45+
const replaceDirect = (hotKey: string, keyCode: string) => {
46+
const hotKeys = hotKey.replace(keyCode, Constants.ZWSP).split("");
47+
hotKeys.forEach((item, index) => {
48+
if (item === Constants.ZWSP) {
49+
hotKeys[index] = keyCode;
6050
}
61-
}
62-
if (/^F(?:1[0-2]|[1-9])$/.test(rest)) {
63-
return [...modifiers, rest];
64-
}
65-
return [...modifiers, rest];
51+
});
52+
return hotKeys;
6653
};
6754

6855
export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
@@ -90,7 +77,26 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
9077
return false;
9178
}
9279

93-
const hotKeys = parseHotKeyTokens(hotKey);
80+
let hotKeys = hotKey.split("");
81+
if (hotKey.indexOf("F") > -1) {
82+
hotKeys.forEach((item, index) => {
83+
if (item === "F") {
84+
// F1-F12
85+
hotKeys[index] = "F" + hotKeys.splice(index + 1, 1);
86+
if (hotKeys[index + 1]) {
87+
hotKeys[index + 1] += hotKeys.splice(index + 1, 1);
88+
}
89+
}
90+
});
91+
} else if (hotKey.indexOf("PageUp") > -1) {
92+
hotKeys = replaceDirect(hotKey, "PageUp");
93+
} else if (hotKey.indexOf("PageDown") > -1) {
94+
hotKeys = replaceDirect(hotKey, "PageDown");
95+
} else if (hotKey.indexOf("Home") > -1) {
96+
hotKeys = replaceDirect(hotKey, "Home");
97+
} else if (hotKey.indexOf("End") > -1) {
98+
hotKeys = replaceDirect(hotKey, "End");
99+
}
94100

95101
// 是否匹配 ⇧[]
96102
if (hotKey.startsWith("⇧") && hotKeys.length === 2) {

0 commit comments

Comments
 (0)