🎨 delete row by keydown

This commit is contained in:
Vanessa 2023-12-15 12:42:34 +08:00
parent a104c94c5f
commit ff0973029d
3 changed files with 40 additions and 32 deletions

View file

@ -5,7 +5,7 @@ import {openEditorTab} from "../../../menus/util";
import {copySubMenu} from "../../../menus/commonMenuItem";
import {getCellText, getTypeByCellElement, popTextCell} from "./cell";
import {getColIconByType, showColMenu} from "./col";
import {insertAttrViewBlockAnimation, setPageSize, stickyRow, updateHeader} from "./row";
import {deleteRow, insertAttrViewBlockAnimation, setPageSize, stickyRow, updateHeader} from "./row";
import {emitOpenMenu} from "../../../plugin/EventBus";
import {addCol} from "./col";
import {openMenuPanel} from "./openMenuPanel";
@ -304,49 +304,23 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
}
rowElement.classList.add("av__row--select");
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
const rowIds: string[] = [];
const blockIds: string[] = [];
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)");
rowElements.forEach(item => {
rowIds.push(item.getAttribute("data-id"));
blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id"));
});
updateHeader(rowElement);
menu.addItem({
icon: "iconTrashcan",
label: window.siyuan.languages.delete,
click() {
const avID = blockElement.getAttribute("data-av-id");
const undoOperations: IOperation[] = [];
rowElements.forEach(item => {
undoOperations.push({
action: "insertAttrViewBlock",
avID,
previousID: item.previousElementSibling?.getAttribute("data-id") || "",
srcIDs: [item.getAttribute("data-id")],
isDetached: item.querySelector('.av__cell[data-detached="true"]') ? true : false,
});
});
transaction(protyle, [{
action: "removeAttrViewBlock",
srcIDs: blockIds,
avID,
}], undoOperations);
rowElements.forEach(item => {
item.remove();
});
stickyRow(blockElement, protyle.contentElement.getBoundingClientRect(), "all");
updateHeader(blockElement.querySelector(".av__row"));
deleteRow(blockElement, protyle);
}
});
if (rowIds.length === 1 && !rowElements[0].querySelector('[data-detached="true"]')) {
if (rowElements.length === 1 && !rowElements[0].querySelector('[data-detached="true"]')) {
menu.addSeparator();
openEditorTab(protyle.app, rowIds[0]);
openEditorTab(protyle.app, rowElements[0].getAttribute("data-id"));
menu.addItem({
label: window.siyuan.languages.copy,
icon: "iconCopy",
type: "submenu",
submenu: copySubMenu(rowIds[0])
submenu: copySubMenu(rowElements[0].getAttribute("data-id"))
});
}
menu.addSeparator();