mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-14 03:04:21 +01:00
This commit is contained in:
parent
94c116499c
commit
845d1dabe8
1 changed files with 73 additions and 68 deletions
|
|
@ -1098,79 +1098,84 @@ export class WYSIWYG {
|
|||
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
|
||||
let moveTarget: boolean | HTMLElement = moveEvent.target as HTMLElement;
|
||||
// table cell select
|
||||
if (tableBlockElement && tableBlockElement.contains(moveTarget) &&
|
||||
if (tableBlockElement &&
|
||||
!hasClosestByClassName(tableBlockElement, "protyle-wysiwyg__embed")) {
|
||||
if (moveTarget.classList.contains("table__select")) {
|
||||
moveTarget.classList.add("fn__none");
|
||||
const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY);
|
||||
moveTarget.classList.remove("fn__none");
|
||||
moveTarget = hasClosestByTag(pointElement, "TH") || hasClosestByTag(pointElement, "TD");
|
||||
}
|
||||
if (moveTarget && moveTarget === target) {
|
||||
tableBlockElement.querySelector(".table__select").removeAttribute("style");
|
||||
protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--hiderange");
|
||||
moveCellElement = moveTarget;
|
||||
return false;
|
||||
}
|
||||
if (moveTarget && (moveTarget.tagName === "TH" || moveTarget.tagName === "TD") &&
|
||||
(!moveCellElement || moveCellElement !== moveTarget)) {
|
||||
// @ts-ignore
|
||||
tableBlockElement.firstElementChild.style.webkitUserModify = "read-only";
|
||||
let width = target.offsetLeft + target.clientWidth - moveTarget.offsetLeft;
|
||||
let left = moveTarget.offsetLeft;
|
||||
if (target.offsetLeft === moveTarget.offsetLeft) {
|
||||
width = Math.max(target.clientWidth, moveTarget.clientWidth);
|
||||
} else if (target.offsetLeft < moveTarget.offsetLeft) {
|
||||
width = moveTarget.offsetLeft + moveTarget.clientWidth - target.offsetLeft;
|
||||
left = target.offsetLeft;
|
||||
if (tableBlockElement.contains(moveTarget)) {
|
||||
if (moveTarget.classList.contains("table__select")) {
|
||||
moveTarget.classList.add("fn__none");
|
||||
const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY);
|
||||
moveTarget.classList.remove("fn__none");
|
||||
moveTarget = hasClosestByTag(pointElement, "TH") || hasClosestByTag(pointElement, "TD");
|
||||
}
|
||||
let height = target.offsetTop + target.clientHeight - moveTarget.offsetTop;
|
||||
let top = moveTarget.offsetTop;
|
||||
if (target.offsetTop === moveTarget.offsetTop) {
|
||||
height = Math.max(target.clientHeight, moveTarget.clientHeight);
|
||||
} else if (target.offsetTop < moveTarget.offsetTop) {
|
||||
height = moveTarget.offsetTop + moveTarget.clientHeight - target.offsetTop;
|
||||
top = target.offsetTop;
|
||||
if (moveTarget && moveTarget === target) {
|
||||
tableBlockElement.querySelector(".table__select").removeAttribute("style");
|
||||
protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--hiderange");
|
||||
moveCellElement = moveTarget;
|
||||
return false;
|
||||
}
|
||||
// https://github.com/siyuan-note/insider/issues/1015
|
||||
Array.from(tableBlockElement.querySelectorAll("th, td")).find((item: HTMLElement) => {
|
||||
const updateWidth = item.offsetLeft < left + width && item.offsetLeft + item.clientWidth > left + width;
|
||||
const updateWidth2 = item.offsetLeft < left && item.offsetLeft + item.clientWidth > left;
|
||||
if (item.offsetTop < top && item.offsetTop + item.clientHeight > top) {
|
||||
if ((item.offsetLeft + 6 > left && item.offsetLeft + item.clientWidth - 6 < left + width) || updateWidth || updateWidth2) {
|
||||
height = top + height - item.offsetTop;
|
||||
top = item.offsetTop;
|
||||
}
|
||||
if (updateWidth) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
}
|
||||
if (updateWidth2) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
}
|
||||
} else if (item.offsetTop < top + height && item.offsetTop + item.clientHeight > top + height) {
|
||||
if ((item.offsetLeft + 6 > left && item.offsetLeft + item.clientWidth - 6 < left + width) || updateWidth || updateWidth2) {
|
||||
height = item.clientHeight + item.offsetTop - top;
|
||||
}
|
||||
if (updateWidth) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
}
|
||||
if (updateWidth2) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
}
|
||||
} else if (updateWidth2 && item.offsetTop + 6 > top && item.offsetTop + item.clientHeight - 6 < top + height) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
} else if (updateWidth && item.offsetTop + 6 > top && item.offsetTop + item.clientHeight - 6 < top + height) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
if (moveTarget && (moveTarget.tagName === "TH" || moveTarget.tagName === "TD") &&
|
||||
(!moveCellElement || moveCellElement !== moveTarget)) {
|
||||
// @ts-ignore
|
||||
tableBlockElement.firstElementChild.style.webkitUserModify = "read-only";
|
||||
let width = target.offsetLeft + target.clientWidth - moveTarget.offsetLeft;
|
||||
let left = moveTarget.offsetLeft;
|
||||
if (target.offsetLeft === moveTarget.offsetLeft) {
|
||||
width = Math.max(target.clientWidth, moveTarget.clientWidth);
|
||||
} else if (target.offsetLeft < moveTarget.offsetLeft) {
|
||||
width = moveTarget.offsetLeft + moveTarget.clientWidth - target.offsetLeft;
|
||||
left = target.offsetLeft;
|
||||
}
|
||||
});
|
||||
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--hiderange");
|
||||
tableBlockElement.querySelector(".table__select").setAttribute("style", `left:${left - tableBlockElement.firstElementChild.scrollLeft}px;top:${top - tableBlockElement.querySelector("table").scrollTop}px;height:${height}px;width:${width + 1}px;`);
|
||||
moveCellElement = moveTarget;
|
||||
let height = target.offsetTop + target.clientHeight - moveTarget.offsetTop;
|
||||
let top = moveTarget.offsetTop;
|
||||
if (target.offsetTop === moveTarget.offsetTop) {
|
||||
height = Math.max(target.clientHeight, moveTarget.clientHeight);
|
||||
} else if (target.offsetTop < moveTarget.offsetTop) {
|
||||
height = moveTarget.offsetTop + moveTarget.clientHeight - target.offsetTop;
|
||||
top = target.offsetTop;
|
||||
}
|
||||
// https://github.com/siyuan-note/insider/issues/1015
|
||||
Array.from(tableBlockElement.querySelectorAll("th, td")).find((item: HTMLElement) => {
|
||||
const updateWidth = item.offsetLeft < left + width && item.offsetLeft + item.clientWidth > left + width;
|
||||
const updateWidth2 = item.offsetLeft < left && item.offsetLeft + item.clientWidth > left;
|
||||
if (item.offsetTop < top && item.offsetTop + item.clientHeight > top) {
|
||||
if ((item.offsetLeft + 6 > left && item.offsetLeft + item.clientWidth - 6 < left + width) || updateWidth || updateWidth2) {
|
||||
height = top + height - item.offsetTop;
|
||||
top = item.offsetTop;
|
||||
}
|
||||
if (updateWidth) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
}
|
||||
if (updateWidth2) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
}
|
||||
} else if (item.offsetTop < top + height && item.offsetTop + item.clientHeight > top + height) {
|
||||
if ((item.offsetLeft + 6 > left && item.offsetLeft + item.clientWidth - 6 < left + width) || updateWidth || updateWidth2) {
|
||||
height = item.clientHeight + item.offsetTop - top;
|
||||
}
|
||||
if (updateWidth) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
}
|
||||
if (updateWidth2) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
}
|
||||
} else if (updateWidth2 && item.offsetTop + 6 > top && item.offsetTop + item.clientHeight - 6 < top + height) {
|
||||
width = left + width - item.offsetLeft;
|
||||
left = item.offsetLeft;
|
||||
} else if (updateWidth && item.offsetTop + 6 > top && item.offsetTop + item.clientHeight - 6 < top + height) {
|
||||
width = item.offsetLeft + item.clientWidth - left;
|
||||
}
|
||||
});
|
||||
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--hiderange");
|
||||
tableBlockElement.querySelector(".table__select").setAttribute("style", `left:${left - tableBlockElement.firstElementChild.scrollLeft}px;top:${top - tableBlockElement.querySelector("table").scrollTop}px;height:${height}px;width:${width + 1}px;`);
|
||||
moveCellElement = moveTarget;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
tableBlockElement.querySelector(".table__select").removeAttribute("style");
|
||||
moveCellElement = undefined;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 在包含 img, video, audio 的元素上划选后无法上下滚动 https://ld246.com/article/1681778773806
|
||||
// 在包含 img, video, audio 的元素上拖拽无法划选 https://github.com/siyuan-note/siyuan/issues/11763
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue