Vanessa 2024-05-17 09:32:50 +08:00
parent 5f9702353f
commit 946fe3d753
2 changed files with 25 additions and 14 deletions

View file

@ -41,9 +41,8 @@ import {unicode2Emoji} from "../../emoji";
import {deleteFiles} from "../../editor/deleteFile";
import {escapeHtml} from "../../util/escape";
import {syncGuide} from "../../sync/syncGuide";
import {getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey";
import {duplicateBlock, getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey";
import {getNextFileLi, getPreviousFileLi} from "../../protyle/wysiwyg/getBlock";
import {hintMoveBlock} from "../../protyle/hint/extend";
import {Backlink} from "../../layout/dock/Backlink";
/// #if !BROWSER
import {setZoom} from "../../layout/topBar";
@ -336,6 +335,21 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
if (!isFileFocus && !event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.duplicate.custom, event)) {
event.preventDefault();
event.stopPropagation();
let selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
if (selectsElement.length === 0) {
const nodeElement = hasClosestBlock(range.startContainer);
if (nodeElement) {
selectsElement = [nodeElement];
}
}
duplicateBlock(selectsElement, protyle);
return true;
}
const target = event.target as HTMLElement;
if (target.tagName !== "TABLE" && ["INPUT", "TEXTAREA"].includes(target.tagName)) {
return false;
@ -607,7 +621,6 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
return true;
}
if (matchHotKey(window.siyuan.config.keymap.general.addToDatabase.custom, event)) {
execByCommand({
command: "addToDatabase",
@ -643,6 +656,15 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
return true;
}
if (isFile && !event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.duplicate.custom, event)) {
event.preventDefault();
event.stopPropagation();
fetchPost("/api/filetree/duplicateDoc", {
id: liElements[0].getAttribute("data-node-id"),
});
return true;
}
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
window.siyuan.menus.menu.remove();
execByCommand({

View file

@ -1439,17 +1439,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.duplicate.custom, event)) {
event.preventDefault();
event.stopPropagation();
let selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
if (selectsElement.length === 0) {
selectsElement = [nodeElement];
}
duplicateBlock(selectsElement, protyle);
return;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.ai.custom, event)) {
event.preventDefault();
event.stopPropagation();