Vanessa 2024-11-21 00:22:20 +08:00
parent 028e3118c4
commit c0b68b1e5e
5 changed files with 121 additions and 96 deletions

View file

@ -72,6 +72,7 @@ import {setReadOnly} from "../../config/util/setReadOnly";
import {copyPNGByLink} from "../../menus/util";
import {globalCommand} from "./command/global";
import {duplicateCompletely} from "../../protyle/render/av/action";
import {copyTextByType} from "../../protyle/toolbar/util";
const switchDialogEvent = (app: App, event: MouseEvent) => {
event.preventDefault();
@ -487,7 +488,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
event.preventDefault();
event.stopPropagation();
if (hasClosestByClassName(range.startContainer, "protyle-title")) {
@ -592,6 +593,12 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
const notebookId = topULElement.getAttribute("data-url");
const pathString = liElements[0].getAttribute("data-path");
const isFile = liElements[0].getAttribute("data-type") === "navigation-file";
const ids: string[] = [];
liElements.forEach(item => {
if (item.getAttribute("data-type") === "navigation-file") {
ids.push(item.getAttribute("data-node-id"));
}
})
if (matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event) && !window.siyuan.config.readonly) {
if (isFile) {
@ -604,25 +611,20 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
openCardByData(app, response.data, "notebook", notebookId, getNotebookName(notebookId));
});
}
event.preventDefault();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.quickMakeCard.custom, event)) {
const blockIDs: string[] = [];
liElements.forEach(item => {
const id = item.getAttribute("data-node-id");
if (id) {
blockIDs.push(id);
}
});
if (blockIDs.length > 0) {
if (ids.length > 0) {
transaction(undefined, [{
action: "addFlashcards",
deckID: Constants.QUICK_DECK_ID,
blockIDs,
blockIDs: ids,
}], [{
action: "removeFlashcards",
deckID: Constants.QUICK_DECK_ID,
blockIDs,
blockIDs: ids,
}]);
}
event.preventDefault();
@ -664,12 +666,54 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
return true;
}
if (isFile && !event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.duplicate.custom, event)) {
if (!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"),
});
ids.forEach(item => {
fetchPost("/api/filetree/duplicateDoc", {
id: item,
});
})
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "ref");
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "blockEmbed");
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocol.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "protocol");
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "protocolMd");
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "hPath");
return true;
}
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) {
event.preventDefault();
event.stopPropagation();
copyTextByType(ids, "id");
return true;
}