This commit is contained in:
parent
a82b9c23fb
commit
a5ca9f1620
3 changed files with 34 additions and 20 deletions
|
@ -7,6 +7,7 @@ import {scrollCenter} from "../../util/highlightById";
|
|||
import {insertEmptyBlock} from "../../block/util";
|
||||
import {removeBlock} from "../wysiwyg/remove";
|
||||
import {hasPreviousSibling} from "../wysiwyg/getBlock";
|
||||
import * as dayjs from "dayjs";
|
||||
|
||||
const scrollToView = (nodeElement: Element, rowElement: HTMLElement, protyle: IProtyle) => {
|
||||
if (nodeElement.getAttribute("custom-pinthead") === "true") {
|
||||
|
@ -721,3 +722,26 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
export const clearTableCell = (protyle: IProtyle, tableBlockElement: HTMLElement) => {
|
||||
if (!tableBlockElement) {
|
||||
return;
|
||||
}
|
||||
const tableSelectElement = tableBlockElement.querySelector(".table__select") as HTMLElement;
|
||||
const selectCellElements: HTMLTableCellElement[] = [];
|
||||
const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
|
||||
tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
|
||||
if (!item.classList.contains("fn__none") &&
|
||||
item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
|
||||
item.offsetTop + 6 > tableSelectElement.offsetTop && item.offsetTop + item.clientHeight - 6 < tableSelectElement.offsetTop + tableSelectElement.clientHeight) {
|
||||
selectCellElements.push(item);
|
||||
}
|
||||
});
|
||||
tableSelectElement.removeAttribute("style");
|
||||
const oldHTML = tableBlockElement.outerHTML;
|
||||
tableBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
selectCellElements.forEach(item => {
|
||||
item.innerHTML = "";
|
||||
});
|
||||
updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ import {isInIOS, isMac, isOnlyMeta, readText} from "../util/compatibility";
|
|||
import {MenuItem} from "../../menus/Menu";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {onGet} from "../util/onGet";
|
||||
import {setTableAlign} from "../util/table";
|
||||
import {clearTableCell, setTableAlign} from "../util/table";
|
||||
import {countBlockWord, countSelectWord} from "../../layout/status";
|
||||
import {showMessage} from "../../dialog/message";
|
||||
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
|
||||
|
@ -1295,25 +1295,9 @@ export class WYSIWYG {
|
|||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.clear,
|
||||
icon: "iconTrashcan",
|
||||
accelerator: "⌦",
|
||||
click() {
|
||||
if (tableBlockElement) {
|
||||
const selectCellElements: HTMLTableCellElement[] = [];
|
||||
const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
|
||||
tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
|
||||
if (!item.classList.contains("fn__none") &&
|
||||
item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
|
||||
item.offsetTop + 6 > tableSelectElement.offsetTop && item.offsetTop + item.clientHeight - 6 < tableSelectElement.offsetTop + tableSelectElement.clientHeight) {
|
||||
selectCellElements.push(item);
|
||||
}
|
||||
});
|
||||
tableSelectElement.removeAttribute("style");
|
||||
const oldHTML = tableBlockElement.outerHTML;
|
||||
tableBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
selectCellElements.forEach(item => {
|
||||
item.innerHTML = "";
|
||||
});
|
||||
updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);
|
||||
}
|
||||
clearTableCell(protyle, tableBlockElement as HTMLElement)
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
@ -33,7 +33,7 @@ import {
|
|||
} from "./getBlock";
|
||||
import {matchHotKey} from "../util/hotKey";
|
||||
import {enter, softEnter} from "./enter";
|
||||
import {fixTable} from "../util/table";
|
||||
import {clearTableCell, fixTable} from "../util/table";
|
||||
import {
|
||||
turnsIntoOneTransaction,
|
||||
turnsIntoTransaction,
|
||||
|
@ -808,6 +808,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return;
|
||||
}
|
||||
} else if (selectText === "") {
|
||||
if (nodeElement.classList.contains("table") && nodeElement.querySelector(".table__select").clientHeight > 0) {
|
||||
clearTableCell(protyle, nodeElement);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const editElement = getContenteditableElement(nodeElement) as HTMLElement;
|
||||
if (!editElement) {
|
||||
nodeElement.classList.add("protyle-wysiwyg--select");
|
||||
|
|
Loading…
Add table
Reference in a new issue