Vanessa 2025-07-23 13:08:38 +08:00
parent c88f99646c
commit 508eb93183
33 changed files with 111 additions and 108 deletions

View file

@ -481,7 +481,7 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
// https://github.com/siyuan-note/insider/issues/536
if (!isCopy && oldSourceParentElement && oldSourceParentElement.classList.contains("list") &&
oldSourceParentElement.getAttribute("data-subtype") === "o" &&
(oldSourceParentElement !== sourceElements[0].parentElement) && oldSourceParentElement.childElementCount > 1) {
oldSourceParentElement !== sourceElements[0].parentElement && oldSourceParentElement.childElementCount > 1) {
Array.from(oldSourceParentElement.children).forEach((item) => {
if (item.classList.contains("protyle-attr")) {
return;
@ -676,7 +676,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
isSameDoc && // 同一文档分屏后oldSourceParentElement 已经被移走,不可再 update https://github.com/siyuan-note/siyuan/issues/8863
oldSourceParentElement && oldSourceParentElement.classList.contains("list") &&
oldSourceParentElement.getAttribute("data-subtype") === "o" &&
(oldSourceParentElement !== sourceElements[0].parentElement) && oldSourceParentElement.childElementCount > 1) {
oldSourceParentElement !== sourceElements[0].parentElement && oldSourceParentElement.childElementCount > 1) {
Array.from(oldSourceParentElement.children).forEach((item) => {
if (item.classList.contains("protyle-attr")) {
return;
@ -1423,7 +1423,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (targetElement && targetElement.getAttribute("data-dtype") === "mAsset" &&
!targetElement.classList.contains("av__cell--header")) {
event.preventDefault(); // 不使用导致无法触发 drop
if (dragoverElement && (targetElement === dragoverElement)) {
if (dragoverElement && targetElement === dragoverElement) {
return;
}
const blockElement = hasClosestBlock(targetElement);
@ -1528,8 +1528,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (targetElement) {
const targetRowElement = hasClosestByClassName(targetElement, "av__row--header");
const dragRowElement = hasClosestByClassName(window.siyuan.dragElement, "av__row--header");
if ((targetElement === window.siyuan.dragElement) || !targetRowElement || !dragRowElement ||
(targetRowElement && dragRowElement && (targetRowElement !== dragRowElement))
if (targetElement === window.siyuan.dragElement || !targetRowElement || !dragRowElement ||
(targetRowElement && dragRowElement && targetRowElement !== dragRowElement)
) {
targetElement = false;
}
@ -1544,7 +1544,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
// gallery item 只能拖拽当前 av 中
const galleryElement = hasClosestByClassName(event.target, "av__gallery");
if (targetElement.classList.contains("av") || !galleryElement ||
!galleryElement.contains(window.siyuan.dragElement) || (targetElement === window.siyuan.dragElement)) {
!galleryElement.contains(window.siyuan.dragElement) || targetElement === window.siyuan.dragElement) {
targetElement = false;
editorElement.querySelectorAll(".dragover__left, .dragover__right").forEach((item: HTMLElement) => {
item.classList.remove("dragover__left", "dragover__right");
@ -1559,7 +1559,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
!targetElement.classList.contains("av__row--util") &&
!targetElement.classList.contains("av__gallery-item") &&
!targetElement.classList.contains("av__gallery-add");
if (targetElement && dragoverElement && (targetElement === dragoverElement)) {
if (targetElement && dragoverElement && targetElement === dragoverElement) {
// 性能优化,目标为同一个元素不再进行校验
const nodeRect = targetElement.getBoundingClientRect();
editorElement.querySelectorAll(".dragover__left, .dragover__right, .dragover__bottom, .dragover__top, .dragover").forEach((item: HTMLElement) => {
@ -1597,11 +1597,12 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
if (targetElement.classList.contains("av__cell")) {
if (event.clientX < nodeRect.left + nodeRect.width / 2 && event.clientX > nodeRect.left &&
!targetElement.classList.contains("av__row") && (targetElement.previousElementSibling !== window.siyuan.dragElement)) {
!targetElement.classList.contains("av__row") && targetElement.previousElementSibling !== window.siyuan.dragElement) {
targetElement.classList.add("dragover__left");
} else if (event.clientX > nodeRect.right - nodeRect.width / 2 && event.clientX <= nodeRect.right + 1 &&
!targetElement.classList.contains("av__row") && (targetElement !== window.siyuan.dragElement.previousElementSibling)) {
if (window.siyuan.dragElement.previousElementSibling.classList.contains("av__colsticky") && (targetElement === window.siyuan.dragElement.previousElementSibling.lastElementChild)) {
!targetElement.classList.contains("av__row") && targetElement !== window.siyuan.dragElement.previousElementSibling) {
if (window.siyuan.dragElement.previousElementSibling.classList.contains("av__colsticky") &&
targetElement === window.siyuan.dragElement.previousElementSibling.lastElementChild) {
// 拖拽到固定列的最后一个元素
} else {
targetElement.classList.add("dragover__right");

View file

@ -403,7 +403,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
}
// 粘贴带样式的行内元素到另一个行内元素中需进行切割
const spanElement = range.startContainer.nodeType === 3 ? range.startContainer.parentElement : range.startContainer as HTMLElement;
if (spanElement.tagName === "SPAN" && (spanElement === (range.endContainer.nodeType === 3 ? range.endContainer.parentElement : range.endContainer)) &&
if (spanElement.tagName === "SPAN" && spanElement === (range.endContainer.nodeType === 3 ? range.endContainer.parentElement : range.endContainer) &&
// 粘贴纯文本不需切割 https://ld246.com/article/1665556907936
// emoji 图片需要切割 https://github.com/siyuan-note/siyuan/issues/9370
tempElement.content.querySelector("span, img")

View file

@ -153,7 +153,8 @@ const setHTML = (options: {
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) {
let removeElement = protyle.wysiwyg.element.firstElementChild as HTMLElement;
const removeElements = [];
while (protyle.wysiwyg.element.childElementCount > 2 && removeElements && (protyle.wysiwyg.element.lastElementChild !== removeElement)) {
while (protyle.wysiwyg.element.childElementCount > 2 && removeElements &&
protyle.wysiwyg.element.lastElementChild !== removeElement) {
if (protyle.contentElement.scrollHeight - removeElement.offsetTop > REMOVED_OVER_HEIGHT) {
removeElements.push(removeElement);
} else {
@ -508,7 +509,7 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
protyle.observer.observe(protyle.wysiwyg.element);
}, 1000 * 3);
if ((focusElement === protyle.wysiwyg.element.firstElementChild) && !hasScrollTop) {
if (focusElement === protyle.wysiwyg.element.firstElementChild && !hasScrollTop) {
protyle.observerLoad.disconnect();
}
};

View file

@ -139,7 +139,7 @@ export const getEditorRange = (element: Element): Range => {
let range: Range;
if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0);
if ((element === range.startContainer) || element.contains(range.startContainer)) {
if (element === range.startContainer || element.contains(range.startContainer)) {
// 有时候点击编辑器头部需要矫正到第一个块中
if (range.toString() === "" && range.startContainer.nodeType === 1 && range.startOffset === 0 &&
(range.startContainer as HTMLElement).classList.contains("protyle-wysiwyg")) {
@ -528,7 +528,7 @@ export const focusByWbr = (element: Element, range: Range) => {
}
} else {
const wbrPreviousSibling = hasPreviousSibling(wbrElement);
if (wbrPreviousSibling && (wbrElement.previousElementSibling === wbrPreviousSibling)) {
if (wbrPreviousSibling && wbrElement.previousElementSibling === wbrPreviousSibling) {
if (wbrElement.previousElementSibling.lastChild?.nodeType === 3) {
// <em>text</em><wbr> 需把光标放在里面,因为 chrome 点击后也是默认在里面
range.setStart(wbrElement.previousElementSibling.lastChild, wbrElement.previousElementSibling.lastChild.textContent.length);

View file

@ -422,7 +422,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
// 表格后无内容时,按右键需新建空块
if (event.key === "ArrowRight" && range.toString() === "" &&
!nodeElement.nextElementSibling &&
(cellElement === nodeElement.querySelector("table").lastElementChild.lastElementChild.lastElementChild) &&
cellElement === nodeElement.querySelector("table").lastElementChild.lastElementChild.lastElementChild &&
getSelectionOffset(cellElement, protyle.wysiwyg.element, range).start === cellElement.textContent.length) {
event.preventDefault();
insertEmptyBlock(protyle, "afterend", nodeElement.getAttribute("data-node-id"));