mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-02 14:58:49 +01:00
This commit is contained in:
parent
fedfd9b320
commit
dd19b9bc44
3 changed files with 77 additions and 74 deletions
|
|
@ -25,6 +25,7 @@ import {openBacklink, openGraph, openOutline, updatePanelByEditor} from "../../e
|
|||
import * as dayjs from "dayjs";
|
||||
import {setTitle} from "../../dialog/processSystem";
|
||||
import {getNoContainerElement} from "../wysiwyg/getBlock";
|
||||
import {commonHotkey} from "../wysiwyg/commonHotkey";
|
||||
|
||||
export class Title {
|
||||
public element: HTMLElement;
|
||||
|
|
@ -82,6 +83,11 @@ export class Title {
|
|||
if (event.isComposing) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (commonHotkey(protyle, event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.key === "ArrowDown" || event.key === "Enter") {
|
||||
const noContainerElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild);
|
||||
// https://github.com/siyuan-note/siyuan/issues/4923
|
||||
|
|
@ -114,32 +120,6 @@ export class Title {
|
|||
writeText(`siyuan://blocks/${protyle.block.rootID}`);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
||||
fetchPost("/api/filetree/getHPathByID", {
|
||||
id: protyle.block.rootID
|
||||
}, (response) => {
|
||||
writeText(response.data);
|
||||
});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openBacklink(protyle);
|
||||
return;
|
||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openGraph(protyle);
|
||||
return;
|
||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const offset = getSelectionOffset(this.editElement);
|
||||
openOutline(protyle);
|
||||
// switchWnd 后,range会被清空,需要重新设置
|
||||
focusByOffset(this.editElement, offset.start, offset.end);
|
||||
return;
|
||||
}
|
||||
});
|
||||
const iconElement = this.element.querySelector(".protyle-title__icon");
|
||||
|
|
|
|||
68
app/src/protyle/wysiwyg/commonHotkey.ts
Normal file
68
app/src/protyle/wysiwyg/commonHotkey.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import {matchHotKey} from "../util/hotKey";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {writeText} from "../util/compatibility";
|
||||
import {openBacklink, openGraph, openOutline} from "../../editor/util";
|
||||
import {focusByOffset, getSelectionOffset} from "../util/selection";
|
||||
import {fullscreen} from "../breadcrumb/action";
|
||||
import {addLoading, setPadding} from "../ui/initUI";
|
||||
import {Constants} from "../../constants";
|
||||
import {onGet} from "../util/onGet";
|
||||
|
||||
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
||||
const target = event.target as HTMLElement
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
||||
fetchPost("/api/filetree/getHPathByID", {
|
||||
id: protyle.block.rootID
|
||||
}, (response) => {
|
||||
writeText(response.data);
|
||||
});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
||||
protyle.title.render(protyle, true);
|
||||
addLoading(protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
mode: 0,
|
||||
size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);
|
||||
});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.fullscreen.custom, event)) {
|
||||
fullscreen(protyle.element);
|
||||
setPadding(protyle);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
if (protyle.model) {
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openBacklink(protyle);
|
||||
return true;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openGraph(protyle);
|
||||
return true;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const offset = getSelectionOffset(target);
|
||||
openOutline(protyle);
|
||||
// switchWnd 后,range会被清空,需要重新设置
|
||||
focusByOffset(target, offset.start, offset.end);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,10 +45,11 @@ import {bindMenuKeydown} from "../../menus/Menu";
|
|||
import {fetchPost} from "../../util/fetch";
|
||||
import {onGet} from "../util/onGet";
|
||||
import {scrollCenter} from "../../util/highlightById";
|
||||
import {openBacklink, openBy, openFileById, openGraph, openOutline} from "../../editor/util";
|
||||
import {openBy, openFileById} from "../../editor/util";
|
||||
import {BlockPanel} from "../../block/Panel";
|
||||
import * as dayjs from "dayjs";
|
||||
import {highlightRender} from "../markdown/highlightRender";
|
||||
import {commonHotkey} from "./commonHotkey";
|
||||
|
||||
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||
|
|
@ -449,19 +450,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
||||
protyle.title.render(protyle, true);
|
||||
addLoading(protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
mode: 0,
|
||||
size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);
|
||||
});
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (matchHotKey("⌘/", event)) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
|
@ -724,13 +712,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.fullscreen.custom, event)) {
|
||||
fullscreen(protyle.element);
|
||||
setPadding(protyle);
|
||||
event.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
|
||||
protyle.undo.undo(protyle);
|
||||
event.preventDefault();
|
||||
|
|
@ -758,13 +739,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
||||
fetchPost("/api/filetree/getHPathByID", {
|
||||
id: protyle.block.rootID
|
||||
}, (response) => {
|
||||
writeText(response.data);
|
||||
});
|
||||
event.preventDefault();
|
||||
if (commonHotkey(protyle, event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1397,26 +1372,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
}
|
||||
}
|
||||
|
||||
if (protyle.model) {
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
||||
event.preventDefault();
|
||||
openOutline(protyle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
||||
event.preventDefault();
|
||||
openBacklink(protyle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
||||
event.preventDefault();
|
||||
openGraph(protyle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// #if !BROWSER
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
|
||||
writeText(clipboard.readText());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue