This commit is contained in:
Vanessa 2023-06-24 21:17:28 +08:00
parent 92ab94bf51
commit 72d0b6409b
4 changed files with 11 additions and 1 deletions

View file

@ -54,6 +54,7 @@ import {fullscreen} from "../protyle/breadcrumb/action";
import {setPadding} from "../protyle/ui/initUI"; import {setPadding} from "../protyle/ui/initUI";
import {openRecentDocs} from "../business/openRecentDocs"; import {openRecentDocs} from "../business/openRecentDocs";
import {App} from "../index"; import {App} from "../index";
import {commandPanel} from "../plugin/commandPanel";
const getRightBlock = (element: HTMLElement, x: number, y: number) => { const getRightBlock = (element: HTMLElement, x: number, y: number) => {
let index = 1; let index = 1;
@ -602,6 +603,11 @@ export const globalShortcut = (app: App) => {
syncGuide(app); syncGuide(app);
return; return;
} }
if (matchHotKey(window.siyuan.config.keymap.general.commandPanel.custom, event)) {
event.preventDefault();
commandPanel(app);
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.editMode.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.general.editMode.custom, event)) {
event.preventDefault(); event.preventDefault();
editor.setReadonly(); editor.setReadonly();

View file

@ -211,6 +211,7 @@ export abstract class Constants {
// "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义 // "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义
public static readonly SIYUAN_KEYMAP: IKeymap = { public static readonly SIYUAN_KEYMAP: IKeymap = {
general: { general: {
commandPanel: {default: "⌥⇧P", custom: "⌥⇧P"},
editMode: {default: "⇧⌘G", custom: "⇧⌘G"}, editMode: {default: "⇧⌘G", custom: "⇧⌘G"},
syncNow: {default: "F9", custom: "F9"}, syncNow: {default: "F9", custom: "F9"},
enterBack: {default: "⌥←", custom: "⌥←"}, enterBack: {default: "⌥←", custom: "⌥←"},

View file

@ -313,6 +313,7 @@ const openPlugin = (app: App, target: Element) => {
}); });
menu.addItem({ menu.addItem({
icon: "iconLayoutBottom", icon: "iconLayoutBottom",
accelerator: window.siyuan.config.keymap.general.commandPanel.custom,
label: window.siyuan.languages.commandPanel, label: window.siyuan.languages.commandPanel,
click() { click() {
commandPanel(app); commandPanel(app);

View file

@ -2,6 +2,7 @@ import {Dialog} from "../dialog";
import {App} from "../index"; import {App} from "../index";
import {upDownHint} from "../util/upDownHint"; import {upDownHint} from "../util/upDownHint";
import {openSetting} from "../config"; import {openSetting} from "../config";
import {updateHotkeyTip} from "../protyle/util/compatibility";
export const commandPanel = (app: App) => { export const commandPanel = (app: App) => {
const dialog = new Dialog({ const dialog = new Dialog({
@ -23,7 +24,7 @@ export const commandPanel = (app: App) => {
const liElement = document.createElement("li"); const liElement = document.createElement("li");
liElement.classList.add("b3-list-item") liElement.classList.add("b3-list-item")
liElement.innerHTML = `<span class="b3-list-item__text">${command.langText || plugin.i18n[command.langKey]}</span> liElement.innerHTML = `<span class="b3-list-item__text">${command.langText || plugin.i18n[command.langKey]}</span>
<span class="b3-list-item__meta">${command.customHotkey}</span>`; <span class="b3-list-item__meta">${updateHotkeyTip(command.customHotkey)}</span>`;
liElement.addEventListener("click", () => { liElement.addEventListener("click", () => {
command.callback(); command.callback();
dialog.destroy(); dialog.destroy();
@ -46,6 +47,7 @@ export const commandPanel = (app: App) => {
} }
const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement; const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement;
inputElement.focus();
inputElement.addEventListener("keydown", (event: KeyboardEvent) => { inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
event.stopPropagation(); event.stopPropagation();
if (event.isComposing) { if (event.isComposing) {