Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/src/boot/globalEvent/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {goBack, goForward} from "../../util/backForward";
import {getDisplayName, getNotebookName} from "../../util/pathName";
import {openFileById} from "../../editor/util";
import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll";
import {getDockHotkey} from "../../layout/dock/hotkey";
import {focusBlock, focusByRange} from "../../protyle/util/selection";
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
import {bindMenuKeydown} from "../../menus/Menu";
Expand Down Expand Up @@ -1232,7 +1233,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
dockHtml += `<li data-type="${item.type}" data-index="${index + 1}" class="b3-list-item">
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
<span class="b3-list-item__text">${item.title}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(item.hotkey || "")}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(getDockHotkey(item))}</span>
</li>`;
});
dockHtml = dockHtml + "</ul>";
Expand Down Expand Up @@ -1371,7 +1372,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
const matchDock = getAllDocks().find(item => {
if (matchHotKey(item.hotkey, event)) {
if (matchHotKey(getDockHotkey(item), event)) {
getDockByType(item.type).toggleModel(item.type);
event.preventDefault();
return true;
Expand Down
3 changes: 2 additions & 1 deletion app/src/business/openRecentDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {escapeHtml} from "../util/escape";
import {isWindow} from "../util/functions";
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
import {getAllDocks} from "../layout/getAll";
import {getDockHotkey} from "../layout/dock/hotkey";
import {Dialog} from "../dialog";
import {focusByRange} from "../protyle/util/selection";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
Expand Down Expand Up @@ -55,7 +56,7 @@ const renderRecentDocsContent = async (data: {
dockHtml += `<li data-type="${item.type}" data-index="${docIndex}" class="b3-list-item${!switchPath ? " b3-list-item--focus" : ""}">
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
<span class="b3-list-item__text">${item.title}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(item.hotkey)}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(getDockHotkey(item))}</span>
</li>`;
if (!switchPath) {
switchPath = item.title;
Expand Down
25 changes: 14 additions & 11 deletions app/src/config/tabs/keymapUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Constants} from "../../constants";
import {hideMessage, showMessage} from "../../dialog/message";
import {fetchPost} from "../../util/fetch";
import {exportLayout} from "../../layout/util";
import {updateDockHotkeyDom} from "../../layout/dock/hotkey";
import {confirmDialog} from "../../dialog/confirmDialog";
import {sendGlobalShortcut, sendUnregisterGlobalShortcut} from "../../boot/globalEvent/keydown";
import {normalizeSearchText} from "../search/normalize";
Expand Down Expand Up @@ -653,24 +654,26 @@ const setKeymapFromDom = (root: HTMLElement) => {
const newHotkey = item.getAttribute("data-value");
if (keys[0] === "general") {
data[keys[0]][keys[1]].custom = newHotkey;
updateDockHotkeyDom(`[data-hotkeylangid="${keys[1]}"]`, newHotkey);
} else if (keys[0] === "editor" && isEditorKeymapSegment(keys[1])) {
data.editor[keys[1]][keys[2]].custom = newHotkey;
} else if (keys[0] === "plugin") {
data.plugin[keys[1]][keys[2]].custom = newHotkey;
const plugin = window.siyuan.ws.app.plugins.find((item) => item.name === keys[1]);
const command = plugin?.commands.find((item) => item.langKey === keys[2]);
if (!command) {
return;
}
/// #if !BROWSER
if (command.globalCallback && command.customHotkey && command.customHotkey !== newHotkey) {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterGlobalShortcut",
accelerator: command.customHotkey,
});
if (command) {
/// #if !BROWSER
if (command.globalCallback && command.customHotkey && command.customHotkey !== newHotkey) {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterGlobalShortcut",
accelerator: command.customHotkey,
});
}
/// #endif
command.customHotkey = newHotkey;
} else if (plugin?.docks[keys[2]]) {
updateDockHotkeyDom(`.dock__item[data-type="${keys[2]}"]`, newHotkey);
}
/// #endif
command.customHotkey = newHotkey;
}
});
const oldToggleWin = window.siyuan.config.keymap.general.toggleWin.custom;
Expand Down
28 changes: 28 additions & 0 deletions app/src/layout/dock/hotkey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {updateHotkeyTip} from "../../protyle/util/compatibility";

export const getDockHotkey = (dock: Config.IUILayoutDockTab): string => {
// 内置 dock 快捷键
if (dock.hotkeyLangId) {
return window.siyuan.config.keymap.general[dock.hotkeyLangId]?.custom ?? "";
}
// 插件 dock 快捷键
for (const plugin of window.siyuan.ws.app.plugins) {
const keymap = window.siyuan.config.keymap.plugin[plugin.name]?.[dock.type];
if (keymap) {
return keymap.custom ?? "";
}
}
return "";
};
Comment on lines +1 to +16

export const genDockItemAriaLabel = (title: string, hotkey: string): string => {
const hotkeyTip = hotkey ? updateHotkeyTip(hotkey) : "";
return `<span style='white-space:pre'>${title} ${hotkeyTip}${window.siyuan.languages.dockTip}</span>`;
};

export const updateDockHotkeyDom = (selector: string, hotkey: string) => {
document.querySelectorAll(selector).forEach((el) => {
const title = el.getAttribute("data-title") || "";
el.setAttribute("aria-label", genDockItemAriaLabel(title, hotkey));
});
};
6 changes: 4 additions & 2 deletions app/src/layout/dock/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {setStorageVal, updateHotkeyTip} from "../../protyle/util/compatibility";
import {setStorageVal} from "../../protyle/util/compatibility";
import {Layout} from "../index";
import {Wnd} from "../Wnd";
import {Tab} from "../Tab";
Expand All @@ -22,6 +22,7 @@ import {Plugin} from "../../plugin";
import {Custom} from "./Custom";
import {clearBeforeResizeTop, recordBeforeResizeTop} from "../../protyle/util/resize";
import {Constants} from "../../constants";
import {getDockHotkey, genDockItemAriaLabel} from "./hotkey";

const TYPES = ["file", "outline", "inbox", "bookmark", "tag", "graph", "globalGraph", "backlink", "agentChat"];

Expand Down Expand Up @@ -890,7 +891,8 @@ export class Dock {
} else if (item.type === "tags") {
item.icon = "iconTag";
}
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>">
const hotkey = getDockHotkey(item);
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="${genDockItemAriaLabel(item.title, hotkey)}">
<svg><use xlink:href="#${item.icon}"></use></svg>
</span>`;
this.data[item.type] = true;
Expand Down
3 changes: 0 additions & 3 deletions app/src/layout/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ const dockToJSON = (dock: Dock) => {
title: item.getAttribute("data-title"),
show: item.classList.contains("dock__item--active"),
icon: item.querySelector("use").getAttribute("xlink:href").substring(1),
hotkey: item.getAttribute("data-hotkey") || "",
hotkeyLangId: item.getAttribute("data-hotkeylangid") || ""
});
});
Expand Down Expand Up @@ -285,8 +284,6 @@ const initInternalDock = (dockItem: Config.IUILayoutDockTab[]) => {
}
if (existSubItem.hotkeyLangId) {
existSubItem.title = window.siyuan.languages[existSubItem.hotkeyLangId];
const km = window.siyuan.config.keymap.general[existSubItem.hotkeyLangId];
existSubItem.hotkey = km ? km.custom : "";
}
});
};
Expand Down
3 changes: 2 additions & 1 deletion app/src/menus/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {isInAndroid, isInHarmony, isInMobileApp, isIPad, setStorageVal, writeTex
import {openCard} from "../card/openCard";
import {openSetting} from "../config";
import {getAllDocks} from "../layout/getAll";
import {getDockHotkey} from "../layout/dock/hotkey";
import {exportLayout, getAllLayout} from "../layout/util";
import {getDockByType} from "../layout/tabUtil";
import {exitSiYuan, lockScreen} from "../dialog/processSystem";
Expand Down Expand Up @@ -161,7 +162,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
dockMenu.push({
id: item.type,
icon: item.icon,
accelerator: item.hotkey,
accelerator: getDockHotkey(item),
label: item.title,
click() {
getDockByType(item.type).toggleModel(item.type);
Expand Down
4 changes: 0 additions & 4 deletions app/src/plugin/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,13 @@ export const addPluginDock = (plugin: Plugin) => {
plugin.docks[key].config = window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key];
}
const dock = plugin.docks[key];
const hotkey = window.siyuan.config.keymap.plugin[plugin.name] ? window.siyuan.config.keymap.plugin[plugin.name][key]?.custom : undefined;
if (dock.config.position.startsWith("Left")) {
window.siyuan.layout.leftDock.genButton([{
type: key,
size: dock.config.size,
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey
}], dock.config.position === "LeftBottom" ? 1 : 0, dock.config.index);
} else if (dock.config.position.startsWith("Bottom")) {
window.siyuan.layout.bottomDock.genButton([{
Expand All @@ -222,7 +220,6 @@ export const addPluginDock = (plugin: Plugin) => {
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey
}], dock.config.position === "BottomRight" ? 1 : 0, dock.config.index);
} else if (dock.config.position.startsWith("Right")) {
window.siyuan.layout.rightDock.genButton([{
Expand All @@ -231,7 +228,6 @@ export const addPluginDock = (plugin: Plugin) => {
show: dock.config.show,
icon: dock.config.icon,
title: dock.config.title,
hotkey
}], dock.config.position === "RightBottom" ? 1 : 0, dock.config.index);
}
});
Expand Down
4 changes: 0 additions & 4 deletions app/src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,6 @@ declare namespace Config {
* SiYuan dock tab data
*/
export interface IUILayoutDockTab {
/**
* Dock tab hotkey
*/
hotkey?: string;
/**
* Hotkey description ID
*/
Expand Down
Loading