From ecf7e4a561f7c9df01effb9352d045f3e58e3f05 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 7 Jan 2024 22:32:41 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/10082 --- app/src/protyle/gutter/index.ts | 2 +- app/src/protyle/render/av/action.ts | 4 ++-- app/src/protyle/render/av/render.ts | 7 +------ app/src/protyle/render/av/row.ts | 14 +++++++++----- app/src/protyle/util/editorCommonEvent.ts | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index d02f8202b..b95212b62 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -231,7 +231,7 @@ export class Gutter { srcIDs, avID, }]); - insertAttrViewBlockAnimation(blockElement, srcIDs, previousID, avID); + insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID); } else { avContextmenu(protyle, rowElement as HTMLElement, { x: gutterRect.left, diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 37db8a57d..40791e4d7 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -85,7 +85,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle srcIDs, avID, }]); - insertAttrViewBlockAnimation(blockElement, srcIDs, undefined, avID); + insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, undefined, avID); event.preventDefault(); event.stopPropagation(); return true; @@ -155,7 +155,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle srcIDs, avID, }]); - insertAttrViewBlockAnimation(blockElement, srcIDs, previousID, avID); + insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID); event.preventDefault(); event.stopPropagation(); return true; diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index cec78e3c9..f96a4bc40 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -291,17 +291,12 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: bool } else { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { item.removeAttribute("data-render"); - const isCurrent = item.querySelector(".av__pulse"); // ctrl+D 后点击添加行 avRender(item, protyle, () => { if (operation.action === "insertAttrViewBlock") { item.querySelectorAll(".av__cell--select").forEach((cellElement: HTMLElement) => { cellElement.classList.remove("av__cell--select"); }); - // https://github.com/siyuan-note/siyuan/issues/9599 - if (!isUndo && operation.isDetached && isCurrent) { - popTextCell(protyle, [item.querySelector(`.av__row[data-id="${operation.srcIDs[0]}"] .av__cell[data-detached="true"]`)], "block"); - } - } else if (operation.action === "addAttrViewCol" && isCurrent) { + } else 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/render/av/row.ts b/app/src/protyle/render/av/row.ts index 60d830e24..f8109124d 100644 --- a/app/src/protyle/render/av/row.ts +++ b/app/src/protyle/render/av/row.ts @@ -2,6 +2,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest"; import {focusBlock} from "../../util/selection"; import {Menu} from "../../../plugin/Menu"; import {transaction} from "../../wysiwyg/transaction"; +import {popTextCell} from "./cell"; export const selectRow = (checkElement: Element, type: "toggle" | "select" | "unselect" | "unselectAll") => { const rowElement = hasClosestByClassName(checkElement, "av__row"); @@ -69,15 +70,15 @@ export const updateHeader = (rowElement: HTMLElement) => { avHeadElement.style.position = "sticky"; }; -export const insertAttrViewBlockAnimation = (blockElement: Element, srcIDs: string[], previousId: string, avId?: string,) => { +export const insertAttrViewBlockAnimation = (protyle: IProtyle, blockElement: Element, srcIDs: string[], previousId: string, avId?: string,) => { const previousElement = blockElement.querySelector(`.av__row[data-id="${previousId}"]`) || blockElement.querySelector(".av__row--header"); - let colHTML = '
'; + let colHTML = '
'; const pinIndex = previousElement.querySelectorAll(".av__colsticky .av__cell").length - 1; if (pinIndex > -1) { - colHTML = '
'; + colHTML = '
'; } previousElement.querySelectorAll(".av__cell").forEach((item: HTMLElement, index) => { - colHTML += `
`; + colHTML += `
`; if (pinIndex === index) { colHTML += "
"; } @@ -90,6 +91,9 @@ export const insertAttrViewBlockAnimation = (blockElement: Element, srcIDs: stri
`; }); previousElement.insertAdjacentHTML("afterend", html); + if (avId) { + popTextCell(protyle, [previousElement.nextElementSibling.querySelector('.av__cell[data-detached="true"]')], "block"); + } const pageSize = parseInt(blockElement.getAttribute("data-page-size")); if (pageSize) { const currentCount = blockElement.querySelectorAll(".av__row:not(.av__row--header)").length; @@ -230,7 +234,7 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => { const avID = blockElement.getAttribute("data-av-id"); const undoOperations: IOperation[] = []; const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)"); - const blockIds:string[] = []; + const blockIds: string[] = []; rowElements.forEach(item => { blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id")); }); diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index 362a5871d..f0487f38a 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -897,7 +897,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { srcIDs: sourceIds, avID, }]); - insertAttrViewBlockAnimation(blockElement, sourceIds, previousID); + insertAttrViewBlockAnimation(protyle, blockElement, sourceIds, previousID); } } } else if (sourceElements.length > 0) { @@ -957,7 +957,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { srcIDs: ids, avID, }]); - insertAttrViewBlockAnimation(blockElement, ids, previousID); + insertAttrViewBlockAnimation(protyle, blockElement, ids, previousID); } } else { for (let i = 0; i < ids.length; i++) {