From 4c230372421c6886e5e758a6cd5070695973e40e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 28 Mar 2024 23:34:11 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/10690 --- app/src/block/popover.ts | 2 +- app/src/protyle/render/av/cell.ts | 10 ++++++++-- app/src/protyle/util/insertHTML.ts | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts index 5affab758..55ee97335 100644 --- a/app/src/block/popover.ts +++ b/app/src/block/popover.ts @@ -34,7 +34,7 @@ export const initBlockPopover = (app: App) => { tip = getCellText(aElement); } } else { - if (aElement.firstElementChild.getAttribute("data-type") === "url") { + if (aElement.firstElementChild?.getAttribute("data-type") === "url") { if (aElement.firstElementChild.textContent.indexOf("...") > -1) { tip = aElement.firstElementChild.getAttribute("data-href"); } diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 396f2deac..36375fb83 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -3,7 +3,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest"; import {openMenuPanel} from "./openMenuPanel"; import {updateAttrViewCellAnimation} from "./action"; import {isNotCtrl} from "../../util/compatibility"; -import {objEquals} from "../../../util/functions"; +import {isDynamicRef, objEquals} from "../../../util/functions"; import {fetchPost} from "../../../util/fetch"; import {focusBlock, focusByRange} from "../../util/selection"; import * as dayjs from "dayjs"; @@ -402,7 +402,13 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type focusByRange(protyle.toolbar.range); cellElements[0].classList.add("av__cell--select"); addDragFill(cellElements[0]); - hintRef(inputElement.value.substring(2), protyle, "av"); + let textPlain = inputElement.value; + if (isDynamicRef(textPlain)) { + textPlain = textPlain.substring(2, 22 + 2) + } else { + textPlain = textPlain.substring(2) + } + hintRef(textPlain, protyle, "av"); avMaskElement?.remove(); event.preventDefault(); event.stopPropagation(); diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index 56ec30365..6d1630336 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -135,6 +135,30 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: } return; } + const contenteditableElement = getContenteditableElement(tempElement.content.firstElementChild); + if (contenteditableElement && contenteditableElement.childNodes.length === 1 && contenteditableElement.firstElementChild?.getAttribute("data-type") === "block-ref") { + const selectCellElement = blockElement.querySelector(".av__cell--select") as HTMLElement + if (selectCellElement) { + const avID = blockElement.dataset.avId; + const sourceId = contenteditableElement.firstElementChild.getAttribute("data-id"); + const previousID = selectCellElement.dataset.blockId; + transaction(protyle, [{ + action: "replaceAttrViewBlock", + avID, + previousID, + nextID: sourceId, + isDetached: false, + }], [{ + action: "replaceAttrViewBlock", + avID, + previousID: sourceId, + nextID: previousID, + isDetached: selectCellElement.dataset.detached === "true", + }]); + return; + } + } + const text = protyle.lute.BlockDOM2EscapeMarkerContent(html); const cellsElement: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--select")); const rowsElement = blockElement.querySelector(".av__row--select");