This commit is contained in:
Vanessa 2022-10-10 19:12:24 +08:00
parent b25e3922de
commit 1d1e224dd2

View file

@ -65,7 +65,7 @@ export const setTableAlign = (protyle: IProtyle, cellElements: HTMLElement[], no
});
}
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
nodeElement.querySelector("wbr").remove();
focusByWbr(tableElement, range)
};
export const insertRow = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => {
@ -203,13 +203,19 @@ export const deleteRow = (protyle: IProtyle, range: Range, cellElement: HTMLElem
};
export const deleteColumn = (protyle: IProtyle, range: Range, nodeElement: Element, cellElement: HTMLElement) => {
range.insertNode(document.createElement("wbr"));
const wbrElement = document.createElement("wbr");
range.insertNode(wbrElement);
const html = nodeElement.outerHTML;
wbrElement.remove();
const index = getColIndex(cellElement);
if (cellElement.previousElementSibling || cellElement.nextElementSibling) {
range.selectNodeContents(cellElement.previousElementSibling || cellElement.nextElementSibling);
const sideCellElement = (cellElement.previousElementSibling || cellElement.nextElementSibling) as HTMLElement
if (sideCellElement) {
range.selectNodeContents(sideCellElement);
range.collapse(true);
range.insertNode(document.createElement("wbr"));
// 滚动条横向定位
if (sideCellElement.offsetLeft + sideCellElement.clientWidth > nodeElement.firstElementChild.scrollLeft + nodeElement.firstElementChild.clientWidth) {
nodeElement.firstElementChild.scrollLeft = sideCellElement.offsetLeft + sideCellElement.clientWidth - nodeElement.firstElementChild.clientWidth;
}
}
const tableElement = nodeElement.querySelector("table");
for (let i = 0; i < tableElement.rows.length; i++) {
@ -222,7 +228,7 @@ export const deleteColumn = (protyle: IProtyle, range: Range, nodeElement: Eleme
}
nodeElement.querySelectorAll("col")[index]?.remove();
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
focusByWbr(nodeElement, range);
focusByRange(range);
};
export const moveRowToUp = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => {
@ -251,6 +257,7 @@ export const moveRowToUp = (protyle: IProtyle, range: Range, cellElement: HTMLEl
}
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
focusByWbr(nodeElement, range);
scrollCenter(protyle, rowElement);
};
export const moveRowToDown = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => {
@ -280,6 +287,7 @@ export const moveRowToDown = (protyle: IProtyle, range: Range, cellElement: HTML
}
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
focusByWbr(nodeElement, range);
scrollCenter(protyle, rowElement);
};
export const moveColumnToLeft = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => {
@ -295,9 +303,14 @@ export const moveColumnToLeft = (protyle: IProtyle, range: Range, cellElement: H
return true;
}
});
nodeElement.querySelectorAll("tr").forEach((trElement) => {
trElement.cells[cellIndex].after(trElement.cells[cellIndex - 1]);
});
// 滚动条横向定位
if (cellElement.offsetLeft < nodeElement.firstElementChild.scrollLeft) {
nodeElement.firstElementChild.scrollLeft = cellElement.offsetLeft;
}
const colElements = nodeElement.querySelectorAll("col");
colElements[cellIndex].after(colElements[cellIndex - 1]);
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
@ -320,6 +333,10 @@ export const moveColumnToRight = (protyle: IProtyle, range: Range, cellElement:
nodeElement.querySelectorAll("tr").forEach((trElement) => {
trElement.cells[cellIndex].before(trElement.cells[cellIndex + 1]);
});
// 滚动条横向定位
if (cellElement.offsetLeft + cellElement.clientWidth > nodeElement.firstElementChild.scrollLeft + nodeElement.firstElementChild.clientWidth) {
nodeElement.firstElementChild.scrollLeft = cellElement.offsetLeft + cellElement.clientWidth - nodeElement.firstElementChild.clientWidth;
}
const colElements = nodeElement.querySelectorAll("col");
colElements[cellIndex].before(colElements[cellIndex + 1]);
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);