Skip to content

Commit 3dbeeff

Browse files
fix(tables): re-sort reorder-columns undo to keep pinned-at-front
If the user reordered, then pinned a column, then undid the reorder, the restored snapshot could leave a currently-pinned column in the middle of columnOrder. pinnedOffsets walks displayColumns left→right and assigns sticky `left` from checkboxColWidth — a pinned column in the middle gets a sticky offset as if it were at the front, causing it to jump over its left neighbors on horizontal scroll. Re-sort the restored order with pinned entries pulled to the front before applying. Mirrors the belt-and-suspenders re-sort in handleColumnDragEnd. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 23b4466 commit 3dbeeff

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

apps/sim/hooks/use-table-undo.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,21 @@ export function useTableUndo({
386386
}
387387

388388
case 'reorder-columns': {
389-
const order = direction === 'undo' ? action.previousOrder : action.newOrder
389+
const restored = direction === 'undo' ? action.previousOrder : action.newOrder
390+
// The user may have pinned/unpinned since the original reorder;
391+
// restoring the raw snapshot can leave a currently-pinned column
392+
// in the middle, which breaks the sticky-offset walk in
393+
// pinnedOffsets and causes the column to jump over its left
394+
// neighbors on scroll.
395+
const pinned = getPinnedColumnsRef.current?.() ?? []
396+
let order = restored
397+
if (pinned.length > 0) {
398+
const pinnedSet = new Set(pinned)
399+
order = [
400+
...restored.filter((n) => pinnedSet.has(n)),
401+
...restored.filter((n) => !pinnedSet.has(n)),
402+
]
403+
}
390404
onColumnOrderChangeRef.current?.(order)
391405
updateMetadataMutation.mutate({ columnOrder: order })
392406
break

0 commit comments

Comments
 (0)