mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
This commit is contained in:
parent
7a9a85ea32
commit
c34d84ce29
@ -54,7 +54,13 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||||||
|
|
||||||
const gutterElement = hasClosestByClassName(event.target, "av__gutters");
|
const gutterElement = hasClosestByClassName(event.target, "av__gutters");
|
||||||
if (gutterElement) {
|
if (gutterElement) {
|
||||||
avContextmenu(protyle, event, gutterElement);
|
const gutterRect = gutterElement.getBoundingClientRect()
|
||||||
|
avContextmenu(protyle, gutterElement.parentElement, {
|
||||||
|
x: gutterRect.left,
|
||||||
|
y: gutterRect.bottom,
|
||||||
|
w: gutterRect.width,
|
||||||
|
h: gutterRect.height
|
||||||
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
@ -205,11 +211,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const avContextmenu = (protyle: IProtyle, event: MouseEvent & { detail: any }, target: HTMLElement) => {
|
export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, position: IPosition) => {
|
||||||
const rowElement = hasClosestByClassName(target, "av__row");
|
|
||||||
if (!rowElement) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (rowElement.classList.contains("av__row--header")) {
|
if (rowElement.classList.contains("av__row--header")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -217,9 +219,6 @@ export const avContextmenu = (protyle: IProtyle, event: MouseEvent & { detail: a
|
|||||||
if (!blockElement) {
|
if (!blockElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
if (!rowElement.classList.contains("av__row--select")) {
|
if (!rowElement.classList.contains("av__row--select")) {
|
||||||
blockElement.querySelectorAll(".av__row--select").forEach(item => {
|
blockElement.querySelectorAll(".av__row--select").forEach(item => {
|
||||||
item.classList.remove("av__row--select");
|
item.classList.remove("av__row--select");
|
||||||
@ -311,15 +310,13 @@ export const avContextmenu = (protyle: IProtyle, event: MouseEvent & { detail: a
|
|||||||
type: "open-menu-av",
|
type: "open-menu-av",
|
||||||
detail: {
|
detail: {
|
||||||
protyle,
|
protyle,
|
||||||
element: hasClosestByClassName(target, "av__cell"),
|
element: blockElement,
|
||||||
|
selectRowElements: rowElements,
|
||||||
},
|
},
|
||||||
separatorPosition: "top",
|
separatorPosition: "top",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu.open({
|
menu.open(position);
|
||||||
x: event.clientX,
|
|
||||||
y: event.clientY,
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -344,7 +344,8 @@ export const openCalcMenu = (protyle: IProtyle, calcElement: HTMLElement) => {
|
|||||||
menu.open({x: calcRect.left, y: calcRect.bottom, h: calcRect.height});
|
menu.open({x: calcRect.left, y: calcRect.bottom, h: calcRect.height});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cellScrollIntoView = (blockElement: HTMLElement, cellRect: DOMRect) => {
|
export const cellScrollIntoView = (blockElement: HTMLElement, cellRect: DOMRect, onlyHeight = true) => {
|
||||||
|
if (!onlyHeight) {
|
||||||
const avScrollElement = blockElement.querySelector(".av__scroll");
|
const avScrollElement = blockElement.querySelector(".av__scroll");
|
||||||
const avScrollRect = avScrollElement.getBoundingClientRect();
|
const avScrollRect = avScrollElement.getBoundingClientRect();
|
||||||
if (avScrollRect.left > cellRect.left) {
|
if (avScrollRect.left > cellRect.left) {
|
||||||
@ -352,12 +353,21 @@ export const cellScrollIntoView = (blockElement: HTMLElement, cellRect: DOMRect)
|
|||||||
} else if (avScrollRect.right < cellRect.right) {
|
} else if (avScrollRect.right < cellRect.right) {
|
||||||
avScrollElement.scrollLeft = avScrollElement.scrollLeft + cellRect.right - avScrollRect.right;
|
avScrollElement.scrollLeft = avScrollElement.scrollLeft + cellRect.right - avScrollRect.right;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const avHeaderRect = blockElement.querySelector(".av__header").getBoundingClientRect()
|
const avHeaderRect = blockElement.querySelector(".av__header").getBoundingClientRect()
|
||||||
if (avHeaderRect.bottom > cellRect.top) {
|
if (avHeaderRect.bottom > cellRect.top) {
|
||||||
const contentElement = hasClosestByClassName(blockElement, "protyle-content");
|
const contentElement = hasClosestByClassName(blockElement, "protyle-content", true);
|
||||||
if (contentElement) {
|
if (contentElement) {
|
||||||
contentElement.scrollTop = contentElement.scrollTop + cellRect.top - avHeaderRect.bottom;
|
contentElement.scrollTop = contentElement.scrollTop + cellRect.top - avHeaderRect.bottom;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const avFooterRect = blockElement.querySelector(".av__row--footer").getBoundingClientRect();
|
||||||
|
if (avFooterRect.top < cellRect.bottom) {
|
||||||
|
const contentElement = hasClosestByClassName(blockElement, "protyle-content", true);
|
||||||
|
if (contentElement) {
|
||||||
|
contentElement.scrollTop = contentElement.scrollTop + cellRect.bottom - avFooterRect.top;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import {matchHotKey} from "../../util/hotKey";
|
import {matchHotKey} from "../../util/hotKey";
|
||||||
import {selectRow} from "./row";
|
import {selectRow} from "./row";
|
||||||
import {cellScrollIntoView, popTextCell} from "./cell";
|
import {cellScrollIntoView, popTextCell} from "./cell";
|
||||||
|
import {avContextmenu} from "./action";
|
||||||
|
|
||||||
export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyle: IProtyle) => {
|
export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyle: IProtyle) => {
|
||||||
if (!nodeElement.classList.contains("av")) {
|
if (!nodeElement.classList.contains("av") || !window.siyuan.menus.menu.element.classList.contains("fn__none")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.isComposing) {
|
if (event.isComposing) {
|
||||||
event.stopPropagation();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 避免浏览器默认快捷键
|
// 避免浏览器默认快捷键
|
||||||
@ -89,7 +89,17 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
|
|||||||
|
|
||||||
const selectRowElements = nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)");
|
const selectRowElements = nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)");
|
||||||
if (selectRowElements.length > 0) {
|
if (selectRowElements.length > 0) {
|
||||||
|
if (matchHotKey("⌘/", event)) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
avContextmenu(protyle, selectRowElements[0] as HTMLElement, {
|
||||||
|
x: nodeElement.querySelector(".layout-tab-bar").getBoundingClientRect().left,
|
||||||
|
y: selectRowElements[0].getBoundingClientRect().bottom
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -99,30 +109,30 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// event.shiftKey
|
// TODO event.shiftKey
|
||||||
if (event.key === "ArrowUp") {
|
if (event.key === "ArrowUp") {
|
||||||
const previousRowElement = selectRowElements[0].previousElementSibling
|
const previousRowElement = selectRowElements[0].previousElementSibling
|
||||||
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
||||||
if (previousRowElement && !previousRowElement.classList.contains("av__row--header")) {
|
if (previousRowElement && !previousRowElement.classList.contains("av__row--header")) {
|
||||||
selectRow(previousRowElement.querySelector(".av__firstcol"), "select");
|
selectRow(previousRowElement.querySelector(".av__firstcol"), "select");
|
||||||
event.preventDefault();
|
cellScrollIntoView(nodeElement, previousRowElement.getBoundingClientRect(), true);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
nodeElement.classList.add("protyle-wysiwyg--select")
|
nodeElement.classList.add("protyle-wysiwyg--select")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (event.key === "ArrowDown") {
|
if (event.key === "ArrowDown") {
|
||||||
const nextRowElement = selectRowElements[selectRowElements.length - 1].nextElementSibling
|
const nextRowElement = selectRowElements[selectRowElements.length - 1].nextElementSibling
|
||||||
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
||||||
if (nextRowElement && !nextRowElement.classList.contains("av__row--add")) {
|
if (nextRowElement && !nextRowElement.classList.contains("av__row--add")) {
|
||||||
selectRow(nextRowElement.querySelector(".av__firstcol"), "select");
|
selectRow(nextRowElement.querySelector(".av__firstcol"), "select");
|
||||||
event.preventDefault();
|
cellScrollIntoView(nodeElement, nextRowElement.getBoundingClientRect(), true);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
nodeElement.classList.add("protyle-wysiwyg--select")
|
nodeElement.classList.add("protyle-wysiwyg--select")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1341,7 +1341,14 @@ export class WYSIWYG {
|
|||||||
}
|
}
|
||||||
const nodeElement = hasClosestBlock(target);
|
const nodeElement = hasClosestBlock(target);
|
||||||
|
|
||||||
if (avContextmenu(protyle, event, target)) {
|
const avRowElement = hasClosestByClassName(target, "av__row")
|
||||||
|
if (avRowElement && avContextmenu(protyle, avRowElement, {
|
||||||
|
x: event.clientX,
|
||||||
|
y: avRowElement.getBoundingClientRect().bottom,
|
||||||
|
h: avRowElement.clientHeight
|
||||||
|
})) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
|
@ -633,7 +633,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
) ||
|
) ||
|
||||||
(!firstEditElement && nodeElement.isSameNode(protyle.wysiwyg.element.firstElementChild))) {
|
(!firstEditElement && nodeElement.isSameNode(protyle.wysiwyg.element.firstElementChild))) {
|
||||||
// 不能用\n判断,否则文字过长折行将错误 https://github.com/siyuan-note/siyuan/issues/6156
|
// 不能用\n判断,否则文字过长折行将错误 https://github.com/siyuan-note/siyuan/issues/6156
|
||||||
if (getSelectionPosition(nodeElement, range).top - protyle.wysiwyg.element.getBoundingClientRect().top < 40) {
|
if (getSelectionPosition(nodeElement, range).top - protyle.wysiwyg.element.getBoundingClientRect().top < 40 || nodeElement.classList.contains("av")) {
|
||||||
if (protyle.title && (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
|
if (protyle.title && (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
|
||||||
protyle.contentElement.scrollTop === 0)) {
|
protyle.contentElement.scrollTop === 0)) {
|
||||||
protyle.title.editElement.focus();
|
protyle.title.editElement.focus();
|
||||||
|
Loading…
Reference in New Issue
Block a user