mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-31 05:48:49 +01:00
This commit is contained in:
parent
e646c4cc3d
commit
da1b02f59b
5 changed files with 67 additions and 61 deletions
|
|
@ -6,9 +6,13 @@ import {initDockMenu} from "./dock";
|
|||
import {initFileMenu, initNavigationMenu} from "./navigation";
|
||||
import {initTabMenu} from "./tab";
|
||||
/// #endif
|
||||
import {Menu, MenuItem} from "./Menu";
|
||||
/// #if !BROWSER
|
||||
import {ipcRenderer} from "electron";
|
||||
/// #endif
|
||||
import {Menu} from "./Menu";
|
||||
import {hasClosestByClassName, hasTopClosestByTag} from "../protyle/util/hasClosest";
|
||||
import {App} from "../index";
|
||||
import {Constants} from "../constants";
|
||||
|
||||
|
||||
export class Menus {
|
||||
|
|
@ -25,11 +29,28 @@ export class Menus {
|
|||
if (hasClosestByClassName(target, "av__panel") && !hasClosestByClassName(target, "b3-menu")) {
|
||||
document.querySelector(".av__panel").dispatchEvent(new CustomEvent("click", {detail: "close"}));
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (target.classList.contains("b3-text-field")) {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONTEXT_MENU, {
|
||||
undo: window.siyuan.languages.undo,
|
||||
redo: window.siyuan.languages.redo,
|
||||
copy: window.siyuan.languages.copy,
|
||||
cut: window.siyuan.languages.cut,
|
||||
delete: window.siyuan.languages.delete,
|
||||
paste: window.siyuan.languages.paste,
|
||||
pasteAsPlainText: window.siyuan.languages.pasteAsPlainText,
|
||||
selectAll: window.siyuan.languages.selectAll,
|
||||
});
|
||||
/// #endif
|
||||
event.stopPropagation();
|
||||
} else {
|
||||
event.preventDefault();
|
||||
}
|
||||
while (target && target.parentElement // ⌃⇥ 后点击会为空
|
||||
&& !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
||||
event.preventDefault();
|
||||
const dataType = target.getAttribute("data-type");
|
||||
if (dataType === "tab-header") {
|
||||
this.unselect();
|
||||
|
|
@ -68,52 +89,6 @@ export class Menus {
|
|||
initDockMenu(target).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-text-field")) {
|
||||
window.siyuan.menus.menu.remove();
|
||||
if ((target as HTMLInputElement).selectionStart !== (target as HTMLInputElement).selectionEnd) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconCopy",
|
||||
accelerator: "⌘C",
|
||||
label: window.siyuan.languages.copy,
|
||||
click: () => {
|
||||
document.execCommand("copy");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconCut",
|
||||
accelerator: "⌘X",
|
||||
label: window.siyuan.languages.cut,
|
||||
click: () => {
|
||||
document.execCommand("cut");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconTrashcan",
|
||||
accelerator: "⌫",
|
||||
label: window.siyuan.languages.delete,
|
||||
click: () => {
|
||||
document.execCommand("delete");
|
||||
}
|
||||
}).element);
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.paste,
|
||||
icon: "iconPaste",
|
||||
accelerator: "⌘V",
|
||||
click: async () => {
|
||||
document.execCommand("paste");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.selectAll,
|
||||
icon: "iconSelect",
|
||||
accelerator: "⌘A",
|
||||
click: () => {
|
||||
document.execCommand("selectAll");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
|
||||
target.focus()
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue