Skip to content

Commit c51e182

Browse files
vch9mathiasbourgoin
authored andcommitted
fix(widgets): table row selection shows full background color
When selection_mode = Row, the entire row should display the selection background color. Previously, only the vertical border characters (│) showed the selection color because: 1. assemble_columns() applied themed_border to each vline separator 2. Each themed_border adds ANSI codes with \033[0m reset suffix 3. themed_selection wraps the assembled row, but reset codes inside clear the selection background 4. Result: only vlines show selection; cell content loses background Fix: Pass ~is_selected flag to assemble_columns. When true, vlines are rendered without themed_border styling, allowing them to inherit the selection background applied to the full row. This affects both wrapped and non-wrapped table rendering paths. BREAKING CHANGE: Bumps version to 0.4.1 for bug fix release.
1 parent efa0ce3 commit c51e182

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
- uses: ocaml/setup-ocaml@v3
1717
with:
1818
ocaml-compiler: 5.3.0
19+
- name: Pin external dependencies
20+
run: opam pin add ppx_forbid git+https://github.com/atacama-dev/ppx_forbid.git --no-action
1921
- name: Install dependencies
2022
run: opam install --deps-only --with-test -y .
2123
- name: Build & test

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [0.4.1] - Unreleased
99

10+
### Fixed
11+
12+
- **Table row selection highlighting**: Full row background now displays correctly when `selection_mode = Row`. Previously, only border characters (vertical separators) showed the selection color due to ANSI reset codes from `themed_border` clearing the selection background. Now, border styling is skipped for selected rows, allowing the full row to inherit the selection background color.
13+
14+
## [0.4.0] - Unreleased
15+
1016
### Breaking Changes
1117

1218
- **Box_widget border style**: added `None_` to `Box_widget.border_style` for borderless containers. Pattern matches on `border_style` may need a new case.

example/demos/table/page.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,7 @@ module Inner = struct
6060
"↑/↓ to move • Enter logs the selection • t opens tutorial • Esc \
6161
returns"
6262
in
63-
let body =
64-
Miaou_widgets_display.Table_widget.render_table_80
65-
~cols:(Some 80)
66-
~header:("Name", "Score", "Status")
67-
~rows:s.table.rows
68-
~cursor:s.table.cursor
69-
~sel_col:0
70-
in
63+
let body = Miaou_widgets_display.Table_widget.Table.render s.table in
7164
header ^ "\n\n" ^ body
7265

7366
let log_selection table =

src/miaou_widgets_display/table_widget.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,12 @@ let render_table_generic_with_opts ?backend ?(wrap = false) ~cols ~header_list
271271
let blank_for_col =
272272
List.mapi (fun idx w -> (idx, String.make w ' ')) col_widths
273273
in
274-
let assemble_columns cols =
274+
let assemble_columns ~is_selected cols =
275275
let buf = Buffer.create inner_w in
276-
let vline = W.themed_border glyphs.vline in
276+
(* When row is selected, don't style vlines - let them inherit selection bg *)
277+
let vline =
278+
if is_selected then glyphs.vline else W.themed_border glyphs.vline
279+
in
277280
Buffer.add_string buf vline ;
278281
List.iteri
279282
(fun idx col ->
@@ -296,7 +299,10 @@ let render_table_generic_with_opts ?backend ?(wrap = false) ~cols ~header_list
296299
^ String.make copts.pad_right ' ')
297300
cols_cells
298301
in
299-
let line_core = assemble_columns cells in
302+
let is_selected =
303+
match opts.selection_mode with Row when i = cursor -> true | _ -> false
304+
in
305+
let line_core = assemble_columns ~is_selected cells in
300306
let line =
301307
match opts.selection_mode with
302308
| Row when i = cursor -> W.themed_selection line_core
@@ -347,7 +353,12 @@ let render_table_generic_with_opts ?backend ?(wrap = false) ~cols ~header_list
347353
| None -> ""))
348354
padded_lines
349355
in
350-
let line_core = assemble_columns cols_for_idx in
356+
let is_selected =
357+
match opts.selection_mode with
358+
| Row when i = cursor -> true
359+
| _ -> false
360+
in
361+
let line_core = assemble_columns ~is_selected cols_for_idx in
351362
let line =
352363
match opts.selection_mode with
353364
| Row when i = cursor -> W.themed_selection line_core

0 commit comments

Comments
 (0)