From 2fa08833792be20e69e765afceb08db67e2eaa1e Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:27:57 +0500 Subject: [PATCH] editor: use tr.scrollIntoView instead of manually adjusting position on new column Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> --- .../editor/src/extensions/table/actions.ts | 1 + .../editor/src/extensions/table/component.tsx | 29 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/packages/editor/src/extensions/table/actions.ts b/packages/editor/src/extensions/table/actions.ts index 97b7fa438..55c84d60b 100644 --- a/packages/editor/src/extensions/table/actions.ts +++ b/packages/editor/src/extensions/table/actions.ts @@ -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; } diff --git a/packages/editor/src/extensions/table/component.tsx b/packages/editor/src/extensions/table/component.tsx index 966507c0b..5158c79ae 100644 --- a/packages/editor/src/extensions/table/component.tsx +++ b/packages/editor/src/extensions/table/component.tsx @@ -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