diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts index f98306918..cc7abd45b 100644 --- a/app/src/block/popover.ts +++ b/app/src/block/popover.ts @@ -23,7 +23,7 @@ export const initBlockPopover = (app: App) => { if (aElement) { let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content"); if (aElement.classList.contains("av__celltext")) { - if (aElement.offsetWidth > aElement.parentElement.clientWidth - 5) { // 只能减左边 padding,换行时字体会穿透到右侧 padding + if (aElement.offsetWidth > aElement.parentElement.clientWidth - (aElement.classList.contains("fn__flex-shrink") ? 19 : 5)) { // 只能减左边 padding,换行时字体会穿透到右侧 padding if (aElement.querySelector(".av__cellicon")) { tip = `${aElement.firstChild.textContent} → ${aElement.lastChild.textContent}`; } else { diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index b95212b62..65df6926e 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -217,6 +217,9 @@ export class Gutter { return; } if (buttonElement.dataset.type === "NodeAttributeViewRow") { + blockElement.querySelectorAll(".av__cell--select").forEach((cellElement: HTMLElement) => { + cellElement.classList.remove("av__cell--select"); + }); const avID = blockElement.getAttribute("data-av-id"); const srcIDs = [Lute.NewNodeID()]; const previousID = event.altKey ? (rowElement.previousElementSibling.getAttribute("data-id") || "") : buttonElement.dataset.rowId; diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 03cfe0466..24991bf0e 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -399,7 +399,10 @@ ${genHintItemHTML(item)} return; } if (this.source === "av") { - const cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell"); + let cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell"); + if (!cellElement) { + cellElement = nodeElement.querySelector(".av__cell--select") as HTMLElement; + } if (!cellElement) { return; } diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index e30fcd9ad..1f53964a1 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -315,8 +315,15 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type inputElement.addEventListener("input", (event: InputEvent) => { if (Constants.BLOCK_HINT_KEYS.includes(inputElement.value.substring(0, 2))) { protyle.toolbar.range = document.createRange(); + if (!blockElement.contains(cellElements[0])) { + const rowElement = hasClosestByClassName(cellElements[0], "av__row") as HTMLElement; + if (cellElements[0]) { + cellElements[0] = blockElement.querySelector(`.av__row[data-id="${rowElement.dataset.id}"] .av__cell[data-col-id="${cellElements[0].dataset.colId}"]`) as HTMLElement; + } + } protyle.toolbar.range.selectNodeContents(cellElements[0].lastChild); focusByRange(protyle.toolbar.range); + cellElements[0].classList.add("av__cell--select"); hintRef(inputElement.value.substring(2), protyle, "av"); avMaskElement?.remove(); event.preventDefault(); diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index a61cd9a76..4a8cbfc98 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -98,7 +98,7 @@ data-icon="${column.icon}" data-dtype="${column.type}" data-wrap="${column.wrap} style="width: ${column.width || "200px"};">
${column.icon ? unicode2Emoji(column.icon, "av__cellheadericon", true) : ``} - ${column.name} + ${column.name} ${column.pin ? '
' : ""}
@@ -292,11 +292,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { item.removeAttribute("data-render"); avRender(item, protyle, () => { - if (operation.action === "insertAttrViewBlock") { - item.querySelectorAll(".av__cell--select").forEach((cellElement: HTMLElement) => { - cellElement.classList.remove("av__cell--select"); - }); - } else if (operation.action === "addAttrViewCol" && item.querySelector(".av__pulse")) { + if (operation.action === "addAttrViewCol" && item.querySelector(".av__pulse")) { openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id}); } }, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id : diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 06ea105e0..966e76c85 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1326,6 +1326,17 @@ export class WYSIWYG { /// #endif return false; } + // 在 span 前面,防止单元格哪 block-ref 被修改 + 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; + } protyle.toolbar.range = getEditorRange(protyle.element); if (target.tagName === "SPAN") { // https://ld246.com/article/1665141518103 let types = protyle.toolbar.getCurrentType(protyle.toolbar.range); @@ -1373,17 +1384,6 @@ export class WYSIWYG { }); return false; } - - 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; - } const nodeElement = hasClosestBlock(target); if (!nodeElement) { return false;