Skip to content

Fix cursor_coordinate going out of bounds into header for empty tables#6413

Closed
Jah-yee wants to merge 1 commit intoTextualize:mainfrom
Jah-yee:fix/empty-table-cursor-bounds
Closed

Fix cursor_coordinate going out of bounds into header for empty tables#6413
Jah-yee wants to merge 1 commit intoTextualize:mainfrom
Jah-yee:fix/empty-table-cursor-bounds

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 11, 2026

When a DataTable is empty (no rows or columns), pressing arrow keys could cause cursor_coordinate to become (-1, 0), which corresponds to the header row. This caused the header cell to be highlighted as if it were a selected data cell.

The issue was in _clamp_cursor_coordinate:

row = clamp(row, 0, self.row_count - 1)

When row_count = 0, this becomes clamp(-1, 0, -1), which returns -1, causing the issue.

Fix: Ensure the maximum bound is never negative:

row = clamp(row, 0, max(0, self.row_count - 1))
column = clamp(column, 0, max(0, len(self.columns) - 1))

Fixes #6411

When a DataTable is empty (no rows or columns), pressing arrow keys
could cause cursor_coordinate to become (-1, 0), which corresponds to
the header row. This caused the header cell to be highlighted as if
it were a selected data cell.

The issue was in _clamp_cursor_coordinate:
  row = clamp(row, 0, self.row_count - 1)

When row_count = 0, this becomes clamp(-1, 0, -1), which returns -1,
causing the issue.

Fix: Ensure the maximum bound is never negative:
  row = clamp(row, 0, max(0, self.row_count - 1))
  column = clamp(column, 0, max(0, len(self.columns) - 1))
@TomJGooding TomJGooding added the duplicate This issue or pull request already exists label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants