From 19d9c455a7ba808ac7a73c62942e786227682fa2 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 21 Feb 2026 11:43:47 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/17002 --- app/src/boot/globalEvent/mousemove.ts | 7 ++++--- app/src/menus/protyle.ts | 25 ++++++++++++++----------- app/src/protyle/gutter/index.ts | 3 ++- app/src/protyle/toolbar/index.ts | 9 +++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/src/boot/globalEvent/mousemove.ts b/app/src/boot/globalEvent/mousemove.ts index f0498813c..1331fe063 100644 --- a/app/src/boot/globalEvent/mousemove.ts +++ b/app/src/boot/globalEvent/mousemove.ts @@ -222,7 +222,8 @@ export const windowMouseMove = (event: MouseEvent, mouseIsEnter: boolean) => { const cellElement = (hasClosestByTag(target, "TH") || hasClosestByTag(target, "TD")) as HTMLTableCellElement; const tableElement = blockElement.querySelector("table"); if (cellElement && tableElement && tableElement.getAttribute("contenteditable") === "true") { - const tableHeight = blockElement.querySelector("table").clientHeight; + const tableHeight = blockElement.querySelector("colgroup").clientHeight; + const captionHeight = blockElement.querySelector("caption")?.clientHeight || 0; const resizeElement = blockElement.querySelector(".table__resize"); if (blockElement.style.textAlign === "center" || blockElement.style.textAlign === "right") { resizeElement.parentElement.style.left = tableElement.offsetLeft + "px"; @@ -232,10 +233,10 @@ export const windowMouseMove = (event: MouseEvent, mouseIsEnter: boolean) => { const rect = cellElement.getBoundingClientRect(); if (rect.right - event.clientX < 3 && rect.right - event.clientX > 0) { resizeElement.setAttribute("data-col-index", (getColIndex(cellElement) + cellElement.colSpan - 1).toString()); - resizeElement.setAttribute("style", `height:${tableHeight}px;left: ${Math.round(cellElement.offsetWidth + cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`); + resizeElement.setAttribute("style", `top:${captionHeight}px;height:${tableHeight}px;left: ${Math.round(cellElement.offsetWidth + cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`); } else if (event.clientX - rect.left < 3 && event.clientX - rect.left > 0 && cellElement.previousElementSibling) { resizeElement.setAttribute("data-col-index", (getColIndex(cellElement) - 1).toString()); - resizeElement.setAttribute("style", `height:${tableHeight}px;left: ${Math.round(cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`); + resizeElement.setAttribute("style", `top:${captionHeight}px;height:${tableHeight}px;left: ${Math.round(cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`); } } } diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index a086f9e9c..054f7f6da 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -716,6 +716,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { /// #else const oldHTML = nodeElement.outerHTML; const id = nodeElement.getAttribute("data-node-id"); + const captionElement = hasClosestByTag(range.startContainer, "CAPTION"); if (range.toString() !== "" || (range.cloneContents().childNodes[0] as HTMLElement)?.classList?.contains("emoji")) { window.siyuan.menus.menu.append(new MenuItem({ id: "copy", @@ -737,7 +738,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { copyPlainText(getSelection().getRangeAt(0).toString()); } }).element); - if (protyle.disabled) { + if (protyle.disabled || captionElement) { return; } window.siyuan.menus.menu.append(new MenuItem({ @@ -820,7 +821,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { } } } - if (!protyle.disabled) { + if (!protyle.disabled && !captionElement) { window.siyuan.menus.menu.append(new MenuItem({ id: "paste", label: window.siyuan.languages.paste, @@ -858,15 +859,17 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { } }).element); } - window.siyuan.menus.menu.append(new MenuItem({ - id: "selectAll", - label: window.siyuan.languages.selectAll, - icon: "iconSelect", - accelerator: "⌘A", - click() { - selectAll(protyle, nodeElement, range); - } - }).element); + if (!captionElement) { + window.siyuan.menus.menu.append(new MenuItem({ + id: "selectAll", + label: window.siyuan.languages.selectAll, + icon: "iconSelect", + accelerator: "⌘A", + click() { + selectAll(protyle, nodeElement, range); + } + }).element); + } if (nodeElement.classList.contains("table") && !protyle.disabled) { const cellElement = hasClosestByTag(range.startContainer, "TD") || hasClosestByTag(range.startContainer, "TH"); if (cellElement) { diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 5db14daf1..e13da9da3 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -1627,7 +1627,8 @@ export class Gutter { if (!tableElement.contains(range.startContainer)) { range = getEditorRange(tableElement.querySelector("th")); } - const cellElement = hasClosestByTag(range.startContainer, "TD") || hasClosestByTag(range.startContainer, "TH"); + const cellElement = hasClosestByTag(range.startContainer, "TD") || + hasClosestByTag(range.startContainer, "TH") || nodeElement.querySelector("th, td"); if (cellElement) { window.siyuan.menus.menu.append(new MenuItem({id: "separator_table", type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({ diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 61341f373..e2381c1b7 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -12,7 +12,7 @@ import { setFirstNodeRange, setLastNodeRange } from "../util/selection"; -import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest"; +import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByTag} from "../util/hasClosest"; import {Link} from "./Link"; import {setPosition} from "../../util/setPosition"; import {transaction, updateTransaction} from "../wysiwyg/transaction"; @@ -114,7 +114,8 @@ export class Toolbar { public render(protyle: IProtyle, range: Range, event?: KeyboardEvent) { this.range = range; let nodeElement = hasClosestBlock(range.startContainer); - if (isMobile() || !nodeElement || protyle.disabled || nodeElement.classList.contains("av")) { + if (isMobile() || !nodeElement || protyle.disabled || nodeElement.classList.contains("av") || + hasClosestByTag(range.startContainer, "CAPTION")) { this.element.classList.add("fn__none"); return; } @@ -1115,7 +1116,7 @@ export class Toolbar { focusBlock(renderElement); renderElement.classList.add("protyle-wysiwyg--select"); } - protyle.wysiwyg.element.focus({ preventScroll: true}); + protyle.wysiwyg.element.focus({preventScroll: true}); return; } let inlineLastNode: Element; @@ -1221,7 +1222,7 @@ export class Toolbar { } } updateTransaction(protyle, id, nodeElement.outerHTML, html); - protyle.wysiwyg.element.focus({ preventScroll: true}); + protyle.wysiwyg.element.focus({preventScroll: true}); }; this.subElement.style.zIndex = (++window.siyuan.zIndex).toString(); this.subElement.classList.remove("fn__none");