Skip to content

Commit ebf6938

Browse files
waleedlatif1claude
andcommitted
fix(tables): scroll-into-view for selection focus, Home/End origin, delete-column undo timing
- Scroll-into-view now tracks selectionFocus (not just anchor), so Shift+Arrow extending selection off-screen properly auto-scrolls - Shift+Home/End now uses the current focus as origin (matching Shift+Arrow behavior) instead of always using anchor - Delete column undo entry is now pushed in onSuccess, preventing a corrupted undo stack if the server rejects the deletion - Dialog copy updated from "cannot be undone" to "You can undo this action" since undo/redo is supported Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f0b5ad6 commit ebf6938

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -899,16 +899,17 @@ export function Table({
899899
}, [])
900900

901901
useEffect(() => {
902-
if (!selectionAnchor) return
903-
const { rowIndex, colIndex } = selectionAnchor
902+
const target = selectionFocus ?? selectionAnchor
903+
if (!target) return
904+
const { rowIndex, colIndex } = target
904905
const rafId = requestAnimationFrame(() => {
905906
const cell = document.querySelector(
906907
`[data-table-scroll] [data-row="${rowIndex}"][data-col="${colIndex}"]`
907908
) as HTMLElement | null
908909
cell?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
909910
})
910911
return () => cancelAnimationFrame(rafId)
911-
}, [selectionAnchor])
912+
}, [selectionAnchor, selectionFocus])
912913

913914
const handleCellClick = useCallback((rowId: string, columnName: string) => {
914915
const column = columnsRef.current.find((c) => c.name === columnName)
@@ -1172,7 +1173,8 @@ export function Table({
11721173
setIsColumnSelection(false)
11731174
const jump = e.metaKey || e.ctrlKey
11741175
if (e.shiftKey) {
1175-
setSelectionFocus({ rowIndex: jump ? 0 : anchor.rowIndex, colIndex: 0 })
1176+
const focus = selectionFocusRef.current ?? anchor
1177+
setSelectionFocus({ rowIndex: jump ? 0 : focus.rowIndex, colIndex: 0 })
11761178
} else {
11771179
setSelectionAnchor({ rowIndex: jump ? 0 : anchor.rowIndex, colIndex: 0 })
11781180
setSelectionFocus(null)
@@ -1185,8 +1187,9 @@ export function Table({
11851187
setIsColumnSelection(false)
11861188
const jump = e.metaKey || e.ctrlKey
11871189
if (e.shiftKey) {
1190+
const focus = selectionFocusRef.current ?? anchor
11881191
setSelectionFocus({
1189-
rowIndex: jump ? totalRows - 1 : anchor.rowIndex,
1192+
rowIndex: jump ? totalRows - 1 : focus.rowIndex,
11901193
colIndex: cols.length - 1,
11911194
})
11921195
} else {
@@ -1728,34 +1731,35 @@ export function Table({
17281731
const orderAtDelete = columnOrderRef.current
17291732
const cols = schemaColumnsRef.current
17301733
const colDef = cols.find((c) => c.name === columnToDelete)
1731-
const colPosition = cols.indexOf(colDef!)
1734+
const colPosition = colDef ? cols.indexOf(colDef) : cols.length
17321735
const currentRows = rowsRef.current
17331736
const cellData = currentRows
17341737
.filter((r) => r.data[columnToDelete] != null)
17351738
.map((r) => ({ rowId: r.id, value: r.data[columnToDelete] }))
17361739
const previousWidth = columnWidthsRef.current[columnToDelete] ?? null
17371740

1738-
pushUndoRef.current({
1739-
type: 'delete-column',
1740-
columnName: columnToDelete,
1741-
columnType: colDef?.type ?? 'string',
1742-
columnPosition: colPosition >= 0 ? colPosition : cols.length,
1743-
columnUnique: colDef?.unique ?? false,
1744-
cellData,
1745-
previousOrder: orderAtDelete ? [...orderAtDelete] : null,
1746-
previousWidth,
1747-
})
1748-
17491741
setDeletingColumn(null)
17501742
deleteColumnMutation.mutate(columnToDelete, {
17511743
onSuccess: () => {
1752-
if (!orderAtDelete) return
1753-
const newOrder = orderAtDelete.filter((n) => n !== columnToDelete)
1754-
setColumnOrder(newOrder)
1755-
updateMetadataRef.current({
1756-
columnWidths: columnWidthsRef.current,
1757-
columnOrder: newOrder,
1744+
pushUndoRef.current({
1745+
type: 'delete-column',
1746+
columnName: columnToDelete,
1747+
columnType: colDef?.type ?? 'string',
1748+
columnPosition: colPosition >= 0 ? colPosition : cols.length,
1749+
columnUnique: colDef?.unique ?? false,
1750+
cellData,
1751+
previousOrder: orderAtDelete ? [...orderAtDelete] : null,
1752+
previousWidth,
17581753
})
1754+
1755+
if (orderAtDelete) {
1756+
const newOrder = orderAtDelete.filter((n) => n !== columnToDelete)
1757+
setColumnOrder(newOrder)
1758+
updateMetadataRef.current({
1759+
columnWidths: columnWidthsRef.current,
1760+
columnOrder: newOrder,
1761+
})
1762+
}
17591763
},
17601764
})
17611765
}, [deletingColumn])
@@ -2240,7 +2244,7 @@ export function Table({
22402244
<span className='text-[var(--text-error)]'>
22412245
This will remove all data in this column.
22422246
</span>{' '}
2243-
This action cannot be undone.
2247+
You can undo this action.
22442248
</p>
22452249
</ModalBody>
22462250
<ModalFooter>

0 commit comments

Comments
 (0)