mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-17 20:48:06 +01:00
🎨 delete row by keydown
This commit is contained in:
parent
a104c94c5f
commit
ff0973029d
3 changed files with 40 additions and 32 deletions
|
|
@ -5,7 +5,7 @@ import {openEditorTab} from "../../../menus/util";
|
||||||
import {copySubMenu} from "../../../menus/commonMenuItem";
|
import {copySubMenu} from "../../../menus/commonMenuItem";
|
||||||
import {getCellText, getTypeByCellElement, popTextCell} from "./cell";
|
import {getCellText, getTypeByCellElement, popTextCell} from "./cell";
|
||||||
import {getColIconByType, showColMenu} from "./col";
|
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 {emitOpenMenu} from "../../../plugin/EventBus";
|
||||||
import {addCol} from "./col";
|
import {addCol} from "./col";
|
||||||
import {openMenuPanel} from "./openMenuPanel";
|
import {openMenuPanel} from "./openMenuPanel";
|
||||||
|
|
@ -304,49 +304,23 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
|
||||||
}
|
}
|
||||||
rowElement.classList.add("av__row--select");
|
rowElement.classList.add("av__row--select");
|
||||||
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
|
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)");
|
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);
|
updateHeader(rowElement);
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
icon: "iconTrashcan",
|
icon: "iconTrashcan",
|
||||||
label: window.siyuan.languages.delete,
|
label: window.siyuan.languages.delete,
|
||||||
click() {
|
click() {
|
||||||
const avID = blockElement.getAttribute("data-av-id");
|
deleteRow(blockElement, protyle);
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (rowIds.length === 1 && !rowElements[0].querySelector('[data-detached="true"]')) {
|
if (rowElements.length === 1 && !rowElements[0].querySelector('[data-detached="true"]')) {
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
openEditorTab(protyle.app, rowIds[0]);
|
openEditorTab(protyle.app, rowElements[0].getAttribute("data-id"));
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
label: window.siyuan.languages.copy,
|
label: window.siyuan.languages.copy,
|
||||||
icon: "iconCopy",
|
icon: "iconCopy",
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
submenu: copySubMenu(rowIds[0])
|
submenu: copySubMenu(rowElements[0].getAttribute("data-id"))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {matchHotKey} from "../../util/hotKey";
|
import {matchHotKey} from "../../util/hotKey";
|
||||||
import {selectRow} from "./row";
|
import {deleteRow, selectRow} from "./row";
|
||||||
import {cellScrollIntoView, popTextCell, updateCellsValue} from "./cell";
|
import {cellScrollIntoView, popTextCell, updateCellsValue} from "./cell";
|
||||||
import {avContextmenu} from "./action";
|
import {avContextmenu} from "./action";
|
||||||
import {hasClosestByClassName} from "../../util/hasClosest";
|
import {hasClosestByClassName} from "../../util/hasClosest";
|
||||||
|
|
@ -132,6 +132,11 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
|
||||||
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (event.key === "Backspace") {
|
||||||
|
event.preventDefault();
|
||||||
|
deleteRow(nodeElement, protyle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
|
||||||
popTextCell(protyle, [selectRowElements[0].querySelector(".av__cell")]);
|
popTextCell(protyle, [selectRowElements[0].querySelector(".av__cell")]);
|
||||||
|
|
|
||||||
|
|
@ -225,3 +225,32 @@ export const setPageSize = (options: {
|
||||||
y: rect.bottom
|
y: rect.bottom
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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[] = [];
|
||||||
|
rowElements.forEach(item => {
|
||||||
|
blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id"));
|
||||||
|
});
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue