-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extend row cursor #6345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend row cursor #6345
Changes from all commits
ca20d02
5b4ac03
cc4ebf6
0a5528f
fefec04
a06a834
d5a4eb2
e0e904f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -268,6 +268,8 @@ class RowRenderables(NamedTuple): | |||||||||
| class DataTable(ScrollView, Generic[CellType], can_focus=True): | ||||||||||
| """A tabular widget that contains data.""" | ||||||||||
|
|
||||||||||
| ALLOW_SELECT = False | ||||||||||
|
|
||||||||||
| BINDINGS: ClassVar[list[BindingType]] = [ | ||||||||||
| Binding("enter", "select_cursor", "Select", show=False), | ||||||||||
| Binding("up", "cursor_up", "Cursor up", show=False), | ||||||||||
|
|
@@ -328,7 +330,6 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): | |||||||||
| color: $foreground; | ||||||||||
| height: auto; | ||||||||||
| max-height: 100%; | ||||||||||
|
|
||||||||||
| &.datatable--fixed-cursor { | ||||||||||
| background: $block-cursor-blurred-background; | ||||||||||
| } | ||||||||||
|
|
@@ -450,7 +451,7 @@ def __init__( | |||||||||
| ) -> None: | ||||||||||
| self.data_table = data_table | ||||||||||
| """The data table.""" | ||||||||||
| self.value: CellType = value | ||||||||||
| self.value = value | ||||||||||
| """The value in the highlighted cell.""" | ||||||||||
| self.coordinate: Coordinate = coordinate | ||||||||||
| """The coordinate of the highlighted cell.""" | ||||||||||
|
|
@@ -1555,7 +1556,7 @@ def _get_row_region(self, row_index: int) -> Region: | |||||||||
| y = sum(ordered_row.height for ordered_row in self.ordered_rows[:row_index]) | ||||||||||
| if self.show_header: | ||||||||||
| y += self.header_height | ||||||||||
| row_region = Region(0, y, row_width, row.height) | ||||||||||
| row_region = Region(0, y, max(self.size.width, row_width), row.height) | ||||||||||
| return row_region | ||||||||||
|
|
||||||||||
| def _get_column_region(self, column_index: int) -> Region: | ||||||||||
|
|
@@ -2357,17 +2358,36 @@ def _render_line_in_row( | |||||||||
| ) | ||||||||||
| remaining_space = max(0, widget_width - table_width) | ||||||||||
| background_color = self.background_colors[1] | ||||||||||
| if row_style.bgcolor is not None: | ||||||||||
| # TODO: This should really be in a component class | ||||||||||
| faded_color = Color.from_rich_color(row_style.bgcolor).blend( | ||||||||||
| background_color, factor=0.25 | ||||||||||
| ) | ||||||||||
| faded_style = Style.from_color( | ||||||||||
| color=row_style.color, bgcolor=faded_color.rich_color | ||||||||||
| if self.cursor_type == "row": | ||||||||||
| extend_style, _ = self._get_styles_to_render_cell( | ||||||||||
| row_index == -1, | ||||||||||
| False, | ||||||||||
| False, | ||||||||||
| should_highlight( | ||||||||||
| hover_location, Coordinate(row_index or 0, 0), cursor_type | ||||||||||
| ), | ||||||||||
| row_index == cursor_location.row, | ||||||||||
| self.show_cursor, | ||||||||||
| self._show_hover_cursor, | ||||||||||
| False, | ||||||||||
| False, | ||||||||||
| ) | ||||||||||
| extend_style = row_style + extend_style | ||||||||||
| else: | ||||||||||
| faded_style = Style.from_color(row_style.color, row_style.bgcolor) | ||||||||||
| scrollable_row.append([Segment(" " * remaining_space, faded_style)]) | ||||||||||
| if row_style.bgcolor is not None: | ||||||||||
| # TODO: This should really be in a component class | ||||||||||
| faded_color = Color.from_rich_color(row_style.bgcolor).blend( | ||||||||||
| background_color, factor=0.25 | ||||||||||
| ) | ||||||||||
| extend_style = Style.from_color( | ||||||||||
| color=row_style.color, bgcolor=faded_color.rich_color | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| extend_style = Style.from_color(row_style.color, row_style.bgcolor) | ||||||||||
| extend_style += Style.from_meta( | ||||||||||
| {"row": row_index, "column": 0, "out_of_bounds": True} | ||||||||||
| ) | ||||||||||
|
Comment on lines
+2387
to
+2389
|
||||||||||
| extend_style += Style.from_meta( | |
| {"row": row_index, "column": 0, "out_of_bounds": True} | |
| ) | |
| extend_style += Style.from_meta({"out_of_bounds": True}) |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new click-selection logic doesn’t account for the out_of_bounds padding segments added during rendering. Since those segments include row/column meta, clicks in the extended whitespace can be misinterpreted as clicks on column 0 / header column 0. Add an out_of_bounds check here and decide whether to ignore the click or map it appropriately (e.g., treat it as a row click when cursor_type == "row").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remaining_spaceis computed fromwidget_width - table_width, buttable_widthcurrently doesn’t include the fixed column widths (only columns fromfixed_columns:plus the row-label width). Whenfixed_columns > 0this overestimates padding and relies on later trimming, which adds unnecessary work per rendered line. Consider basing the calculation on the full table width (row labels + all columns) or otherwise accounting for fixed columns.