mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 17:40:42 +08:00
This commit is contained in:
parent
658193a86f
commit
4ed5d8c987
@ -1098,25 +1098,27 @@ export class WYSIWYG {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let beforeContextmenuRange: Range;
|
let beforeContextmenuRange: Range;
|
||||||
this.element.addEventListener("contextmenu", (event) => {
|
this.element.addEventListener("contextmenu", (event: MouseEvent & { detail: any }) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const x = event.clientX || event.detail.x
|
||||||
|
const y = event.clientY || event.detail.y
|
||||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
||||||
if (selectElements.length > 1) {
|
if (selectElements.length > 1) {
|
||||||
// 多选块
|
// 多选块
|
||||||
hideElements(["util"], protyle);
|
hideElements(["util"], protyle);
|
||||||
protyle.gutter.renderMenu(protyle, selectElements[0]);
|
protyle.gutter.renderMenu(protyle, selectElements[0]);
|
||||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
|
window.siyuan.menus.menu.popup({x, y});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const target = event.target as HTMLElement;
|
const target = event.detail.target || event.target as HTMLElement
|
||||||
const embedElement = hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed");
|
const embedElement = hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed");
|
||||||
if (embedElement) {
|
if (embedElement) {
|
||||||
if (getSelection().rangeCount === 0) {
|
if (getSelection().rangeCount === 0) {
|
||||||
focusSideBlock(embedElement);
|
focusSideBlock(embedElement);
|
||||||
}
|
}
|
||||||
protyle.gutter.renderMenu(protyle, embedElement);
|
protyle.gutter.renderMenu(protyle, embedElement);
|
||||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
|
window.siyuan.menus.menu.popup({x, y});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (protyle.disabled) {
|
if (protyle.disabled) {
|
||||||
@ -1154,8 +1156,8 @@ export class WYSIWYG {
|
|||||||
}
|
}
|
||||||
if (target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
if (target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
||||||
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
||||||
clientX: event.clientX + 4,
|
clientX: x + 4,
|
||||||
clientY: event.clientY
|
clientY: y
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1167,7 +1169,7 @@ export class WYSIWYG {
|
|||||||
(isMobile() || beforeContextmenuRange && nodeElement.contains(beforeContextmenuRange.startContainer))) {
|
(isMobile() || beforeContextmenuRange && nodeElement.contains(beforeContextmenuRange.startContainer))) {
|
||||||
if (!isMobile() || protyle.toolbar?.element.classList.contains("fn__none")) {
|
if (!isMobile() || protyle.toolbar?.element.classList.contains("fn__none")) {
|
||||||
contentMenu(protyle, nodeElement);
|
contentMenu(protyle, nodeElement);
|
||||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 13, h: 26});
|
window.siyuan.menus.menu.popup({x, y: y + 13, h: 26});
|
||||||
protyle.toolbar?.element.classList.add("fn__none");
|
protyle.toolbar?.element.classList.add("fn__none");
|
||||||
if (nodeElement.classList.contains("table")) {
|
if (nodeElement.classList.contains("table")) {
|
||||||
nodeElement.querySelector("table").classList.remove("select");
|
nodeElement.querySelector("table").classList.remove("select");
|
||||||
@ -1179,7 +1181,7 @@ export class WYSIWYG {
|
|||||||
if (protyle.gutter) {
|
if (protyle.gutter) {
|
||||||
protyle.gutter.renderMenu(protyle, nodeElement);
|
protyle.gutter.renderMenu(protyle, nodeElement);
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
|
window.siyuan.menus.menu.popup({x, y});
|
||||||
protyle.toolbar?.element.classList.add("fn__none");
|
protyle.toolbar?.element.classList.add("fn__none");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
focusByRange,
|
focusByRange,
|
||||||
focusByWbr,
|
focusByWbr,
|
||||||
getEditorRange,
|
getEditorRange,
|
||||||
getSelectionOffset,
|
getSelectionOffset, getSelectionPosition,
|
||||||
selectAll,
|
selectAll,
|
||||||
setFirstNodeRange,
|
setFirstNodeRange,
|
||||||
setLastNodeRange
|
setLastNodeRange
|
||||||
@ -1628,6 +1628,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.key === "ContextMenu") {
|
||||||
|
const rangePosition = getSelectionPosition(nodeElement, range);
|
||||||
|
protyle.wysiwyg.element.dispatchEvent(new CustomEvent("contextmenu", {
|
||||||
|
detail: {
|
||||||
|
target: nodeElement,
|
||||||
|
y: rangePosition.top + 8,
|
||||||
|
x: rangePosition.left
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
|
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
|
||||||
if (refElement) {
|
if (refElement) {
|
||||||
|
Loading…
Reference in New Issue
Block a user