editor: use tr.scrollIntoView instead of manually adjusting position on new column

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2026-03-31 11:27:57 +05:00
parent 8eca88a054
commit 2fa0883379
2 changed files with 1 additions and 29 deletions

View File

@@ -192,6 +192,7 @@ function selectColumn(
direction === "prev" ? currentCellIndex - 1 : currentCellIndex + 1;
const pos = rect.map.map[nextCellIndex - 1];
tr.setSelection(new TextSelection(tr.doc.resolve(rect.tableStart + pos + 1)));
tr.scrollIntoView();
return true;
}

View File

@@ -60,35 +60,6 @@ export function TableComponent(
);
}, [node, cellMinWidth]);
useEffect(() => {
function onSelectionUpdate() {
if (!tableRef?.current) return;
const scrollContainer = tableRef.current.parentElement;
if (!scrollContainer) return;
const currentCell = findSelectedDOMNode(editor, [
"tableCell",
"tableHeader"
]);
if (!currentCell || !tableRef.current.contains(currentCell)) return;
const cellRect = currentCell.getBoundingClientRect();
const containerRect = scrollContainer.getBoundingClientRect();
if (cellRect.right > containerRect.right) {
scrollContainer.scrollLeft += cellRect.right - containerRect.right;
} else if (cellRect.left < containerRect.left) {
scrollContainer.scrollLeft -= containerRect.left - cellRect.left;
}
}
editor.on("selectionUpdate", onSelectionUpdate);
return () => {
editor.off("selectionUpdate", onSelectionUpdate);
};
}, []);
// useEffect(() => {
// function transactionListener({
// editor