Vanessa 2023-10-13 13:55:27 +08:00
parent 1815ec1b39
commit 7a9a85ea32
2 changed files with 36 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import {matchHotKey} from "../../util/hotKey"; import {matchHotKey} from "../../util/hotKey";
import {selectRow, updateHeader} from "./row"; import {selectRow} from "./row";
import {cellScrollIntoView, popTextCell} from "./cell"; import {cellScrollIntoView, popTextCell} from "./cell";
export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyle: IProtyle) => { export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyle: IProtyle) => {
@ -87,17 +87,42 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
} }
} }
const selectRowElement = nodeElement.querySelector(".av__row--select:not(.av__row--header)") as HTMLElement; const selectRowElements = nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)");
if (selectRowElement) { if (selectRowElements.length > 0) {
if (event.key === "Escape") { if (event.key === "Escape") {
selectRowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconUncheck"); selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
selectRowElement.classList.remove("av__row--select"); return true;
updateHeader(selectRowElement); }
if (event.key === "Enter") {
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
popTextCell(protyle, [selectRowElements[0].querySelector(".av__cell")]);
event.preventDefault();
return true; return true;
} }
// event.shiftKey // event.shiftKey
if (event.key === "ArrowUp") { if (event.key === "ArrowUp") {
return true; const previousRowElement = selectRowElements[0].previousElementSibling
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
if (previousRowElement && !previousRowElement.classList.contains("av__row--header")) {
selectRow(previousRowElement.querySelector(".av__firstcol"), "select");
event.preventDefault();
return true;
} else {
nodeElement.classList.add("protyle-wysiwyg--select")
return false
}
}
if (event.key === "ArrowDown") {
const nextRowElement = selectRowElements[selectRowElements.length - 1].nextElementSibling
selectRow(selectRowElements[0].querySelector(".av__firstcol"), "unselectAll");
if (nextRowElement && !nextRowElement.classList.contains("av__row--add")) {
selectRow(nextRowElement.querySelector(".av__firstcol"), "select");
event.preventDefault();
return true;
} else {
nodeElement.classList.add("protyle-wysiwyg--select")
return false
}
} }
} }
return false; return false;

View File

@ -1,9 +1,10 @@
import {hasClosestBlock} from "../../util/hasClosest"; import {hasClosestBlock} from "../../util/hasClosest";
import {focusBlock} from "../../util/selection";
export const selectRow = (checkElement: Element, type: "toggle" | "select" | "unselect") => { export const selectRow = (checkElement: Element, type: "toggle" | "select" | "unselect" | "unselectAll") => {
const rowElement = checkElement.parentElement; const rowElement = checkElement.parentElement;
const useElement = checkElement.querySelector("use"); const useElement = checkElement.querySelector("use");
if (rowElement.classList.contains("av__row--header")) { if (rowElement.classList.contains("av__row--header") || type === "unselectAll") {
if ("#iconCheck" === useElement.getAttribute("xlink:href")) { if ("#iconCheck" === useElement.getAttribute("xlink:href")) {
rowElement.parentElement.querySelectorAll(".av__firstcol").forEach(item => { rowElement.parentElement.querySelectorAll(".av__firstcol").forEach(item => {
item.querySelector("use").setAttribute("xlink:href", "#iconUncheck"); item.querySelector("use").setAttribute("xlink:href", "#iconUncheck");
@ -24,6 +25,7 @@ export const selectRow = (checkElement: Element, type: "toggle" | "select" | "un
useElement.setAttribute("xlink:href", "#iconUncheck"); useElement.setAttribute("xlink:href", "#iconUncheck");
} }
} }
focusBlock(hasClosestBlock(rowElement) as HTMLElement);
updateHeader(rowElement); updateHeader(rowElement);
} }