mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-07-11 21:09:37 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user