treemd 0.5.10

A markdown navigator with tree-based structural navigation and syntax highlighting
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
//! Table rendering for the TUI
//!
//! Handles rendering of markdown tables with proper alignment,
//! borders, selection highlighting, and cell navigation.

use crate::parser::output::Alignment;
use crate::tui::theme::Theme;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use unicode_width::UnicodeWidthStr;

use crate::tui::ui::util::{align_text, wrap_text};

/// Context for rendering a table row
pub struct TableRenderContext<'a> {
    pub theme: &'a Theme,
    pub row_num: usize,
    pub is_header: bool,
    pub in_table_mode: bool,
    pub is_table_selected: bool,
    pub selected_cell: Option<(usize, usize)>,
}

/// Minimum column width (including padding) to maintain readability
const MIN_COL_WIDTH: usize = 3;

/// Calculate column widths using content-weighted area approach
///
/// Instead of using max cell width, use average cell width weighted by content.
/// This gives fairer distribution when one column has a single outlier value.
fn calculate_column_widths(headers: &[String], rows: &[Vec<String>]) -> Vec<usize> {
    let col_count = headers.len();

    if rows.is_empty() {
        // No data rows, use header widths
        return headers.iter().map(|h| h.width().max(1)).collect();
    }

    let mut col_widths: Vec<usize> = vec![0; col_count];

    // Calculate average width per column from data rows (not headers)
    // This focuses on actual content, as forthrin suggested
    for (i, _header) in headers.iter().enumerate() {
        let mut total_width = 0usize;
        let mut cell_count = 0usize;
        let mut max_width = 0usize;

        for row in rows {
            if let Some(cell) = row.get(i) {
                let cell_width = cell.width();
                total_width += cell_width;
                cell_count += 1;
                max_width = max_width.max(cell_width);
            }
        }

        if cell_count > 0 {
            // Use weighted average: blend of average and max
            // This prevents one outlier from dominating but ensures content fits
            let avg_width = total_width / cell_count;
            // Weight: 70% average, 30% max - balances fairness with readability
            col_widths[i] = (avg_width * 7 + max_width * 3) / 10;
        }

        // Ensure column is at least as wide as header
        col_widths[i] = col_widths[i].max(headers[i].width()).max(1);
    }

    col_widths
}

/// Render a complete table with headers, alignments, and rows
///
/// # Arguments
/// * `headers` - Column headers
/// * `alignments` - Column alignments
/// * `rows` - Data rows
/// * `theme` - Color theme
/// * `is_selected` - Whether the table element is selected
/// * `in_table_mode` - Whether we're in table cell navigation mode
/// * `selected_cell` - Currently selected cell (row, col) if in table mode
/// * `available_width` - Optional maximum width to constrain table to
#[allow(clippy::too_many_arguments)]
pub fn render_table(
    headers: &[String],
    alignments: &[Alignment],
    rows: &[Vec<String>],
    theme: &Theme,
    is_selected: bool,
    in_table_mode: bool,
    selected_cell: Option<(usize, usize)>,
    available_width: Option<u16>,
) -> Vec<Line<'static>> {
    let mut lines = Vec::new();

    if headers.is_empty() {
        return lines;
    }

    let col_count = headers.len();

    // Calculate column widths using content-weighted approach
    let mut col_widths = calculate_column_widths(headers, rows);

    // Start with normal padding (1 space each side = 2 total)
    let mut padding = 2usize;

    // Add initial padding
    for width in &mut col_widths {
        *width += padding;
    }

    // Smart table collapsing: shrink columns proportionally if table is too wide
    if let Some(max_width) = available_width {
        let max_width = max_width as usize;
        let prefix_width = if in_table_mode || is_selected { 2 } else { 0 };
        let border_width = col_count + 1; // │ between and around columns

        // Try shrinking with progressively less padding
        loop {
            let total_width: usize = col_widths.iter().sum::<usize>() + border_width + prefix_width;

            if total_width <= max_width || max_width <= border_width + prefix_width {
                break;
            }

            // Available space for column content
            let available_for_cols = max_width.saturating_sub(border_width + prefix_width);
            let current_col_total: usize = col_widths.iter().sum();

            if current_col_total == 0 {
                break;
            }

            // Check if we can fit by reducing padding first (before shrinking content)
            if padding > 0 {
                let potential_savings = col_count * padding;
                if total_width - potential_savings <= max_width {
                    // Reducing padding is enough - recalculate with less padding
                    let needed_reduction = total_width - max_width;
                    // Ensure at least 1 reduction per iteration to avoid infinite loop
                    let padding_reduction = (needed_reduction / col_count).max(1).min(padding);
                    for width in &mut col_widths {
                        *width = width.saturating_sub(padding_reduction);
                    }
                    padding = padding.saturating_sub(padding_reduction);
                    continue;
                }
                // Remove all padding and try again
                for width in &mut col_widths {
                    *width = width.saturating_sub(padding);
                }
                padding = 0;
                continue;
            }

            // Padding exhausted, now shrink columns proportionally
            let shrink_ratio = available_for_cols as f64 / current_col_total as f64;
            for width in &mut col_widths {
                let new_width = ((*width as f64) * shrink_ratio) as usize;
                *width = new_width.max(MIN_COL_WIDTH);
            }

            // Iterative trim: MIN_COL_WIDTH clamping can push total back over budget.
            // Repeatedly reduce the widest column by 1 until we fit.
            let mut total_after: usize = col_widths.iter().sum();
            while total_after > available_for_cols {
                if let Some(max_idx) = col_widths
                    .iter()
                    .enumerate()
                    .filter(|(_, w)| **w > MIN_COL_WIDTH)
                    .max_by_key(|(_, w)| **w)
                    .map(|(i, _)| i)
                {
                    col_widths[max_idx] -= 1;
                    total_after -= 1;
                } else {
                    break; // All columns at minimum, can't shrink further
                }
            }
            break;
        }
    }

    // Top border (add selection indicator or spacing)
    let mut top_border_spans = vec![];

    if in_table_mode {
        // In table mode, add spacing to align with row arrows
        top_border_spans.push(Span::raw("  "));
    } else if is_selected {
        // Not in table nav mode: show arrow if table is selected as element
        top_border_spans.push(Span::styled(
            "",
            Style::default()
                .fg(theme.selection_indicator_fg)
                .bg(theme.selection_indicator_bg)
                .add_modifier(Modifier::BOLD),
        ));
    }

    let mut top_border = String::from("");
    for (i, &width) in col_widths.iter().enumerate() {
        top_border.push_str(&"".repeat(width));
        if i < col_widths.len() - 1 {
            top_border.push('');
        }
    }
    top_border.push('');
    top_border_spans.push(Span::styled(
        top_border,
        Style::default().fg(theme.table_border),
    ));
    lines.push(Line::from(top_border_spans));

    // Header row (row 0)
    let header_lines = render_table_row(
        headers,
        &col_widths,
        alignments,
        &TableRenderContext {
            theme,
            row_num: 0,
            is_header: true,
            in_table_mode,
            is_table_selected: is_selected,
            selected_cell,
        },
    );
    lines.extend(header_lines);

    // Header separator
    let mut separator_spans = vec![];
    if in_table_mode || is_selected {
        separator_spans.push(Span::raw("  "));
    }
    let mut separator = String::from("");
    for (i, &width) in col_widths.iter().enumerate() {
        separator.push_str(&"".repeat(width));
        if i < col_widths.len() - 1 {
            separator.push('');
        }
    }
    separator.push('');
    separator_spans.push(Span::styled(
        separator,
        Style::default().fg(theme.table_border),
    ));
    lines.push(Line::from(separator_spans));

    // Data rows
    for (row_idx, row) in rows.iter().enumerate() {
        let data_row = row_idx + 1; // +1 because row 0 is header
        let row_lines = render_table_row(
            row,
            &col_widths,
            alignments,
            &TableRenderContext {
                theme,
                row_num: data_row,
                is_header: false,
                in_table_mode,
                is_table_selected: is_selected,
                selected_cell,
            },
        );
        lines.extend(row_lines);
    }

    // Bottom border
    let mut bottom_border_spans = vec![];
    if in_table_mode || is_selected {
        bottom_border_spans.push(Span::raw("  "));
    }
    let mut bottom_border = String::from("");
    for (i, &width) in col_widths.iter().enumerate() {
        bottom_border.push_str(&"".repeat(width));
        if i < col_widths.len() - 1 {
            bottom_border.push('');
        }
    }
    bottom_border.push('');
    bottom_border_spans.push(Span::styled(
        bottom_border,
        Style::default().fg(theme.table_border),
    ));
    lines.push(Line::from(bottom_border_spans));

    lines
}

/// Render a single table row with proper alignment and styling
/// Supports multi-line cells via wrapping.
///
/// # Arguments
/// * `cells` - Cell contents for this row
/// * `col_widths` - Pre-calculated column widths
/// * `alignments` - Column alignments
/// * `ctx` - Rendering context with theme and selection state
pub fn render_table_row(
    cells: &[String],
    col_widths: &[usize],
    alignments: &[Alignment],
    ctx: &TableRenderContext,
) -> Vec<Line<'static>> {
    // 1. Wrap each cell into multiple lines
    let mut wrapped_cells: Vec<Vec<String>> = Vec::new();
    let mut max_lines = 1;

    for (i, cell) in cells.iter().enumerate() {
        let width = col_widths.get(i).copied().unwrap_or(10);
        // Available width for content is width - 2 (for padding)
        let content_width = width.saturating_sub(2);
        let wrapped = if content_width > 0 {
            wrap_text(cell, content_width)
        } else {
            vec![String::new()]
        };
        max_lines = max_lines.max(wrapped.len());
        wrapped_cells.push(wrapped);
    }

    // 2. Render each line of the row
    let mut row_lines = Vec::new();

    for line_idx in 0..max_lines {
        let mut spans = Vec::new();

        // Add arrow or space to keep table aligned
        if ctx.in_table_mode {
            let is_selected_row = ctx.selected_cell.map(|(r, _)| r) == Some(ctx.row_num);
            if is_selected_row && line_idx == 0 {
                spans.push(Span::styled(
                    "",
                    Style::default()
                        .fg(ctx.theme.selection_indicator_fg)
                        .add_modifier(Modifier::BOLD),
                ));
            } else {
                spans.push(Span::raw("  "));
            }
        } else if ctx.is_table_selected {
            spans.push(Span::raw("  "));
        }

        spans.push(Span::styled(
            "",
            Style::default().fg(ctx.theme.table_border),
        ));

        for (i, wrapped_cell) in wrapped_cells.iter().enumerate() {
            let width = col_widths.get(i).copied().unwrap_or(10);
            let alignment = alignments.get(i).unwrap_or(&Alignment::Left);

            // Get the text for this specific line of the cell, or empty string
            let line_text = wrapped_cell.get(line_idx).cloned().unwrap_or_default();
            let cell_text = align_text(&line_text, width, alignment);

            // Determine if this specific cell is selected
            let is_selected = ctx.selected_cell == Some((ctx.row_num, i));

            let style = if is_selected {
                Style::default()
                    .fg(ctx.theme.link_selected_fg)
                    .bg(ctx.theme.link_selected_bg)
                    .add_modifier(Modifier::BOLD)
            } else if ctx.is_header {
                Style::default()
                    .fg(ctx.theme.heading_color(3))
                    .add_modifier(Modifier::BOLD)
            } else {
                ctx.theme.text_style()
            };

            spans.push(Span::styled(cell_text, style));
            spans.push(Span::styled(
                "",
                Style::default().fg(ctx.theme.table_border),
            ));
        }

        row_lines.push(Line::from(spans));
    }

    row_lines
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::tui::theme::ThemeName;

    fn test_theme() -> Theme {
        Theme::from_name(ThemeName::OceanDark)
    }

    mod render_table_tests {
        use super::*;

        #[test]
        fn test_empty_headers_returns_empty() {
            let theme = test_theme();
            let lines = render_table(&[], &[], &[], &theme, false, false, None, None);
            assert!(lines.is_empty());
        }

        #[test]
        fn test_single_column_table() {
            let theme = test_theme();
            let headers = vec!["Name".to_string()];
            let alignments = vec![Alignment::Left];
            let rows = vec![vec!["Alice".to_string()], vec!["Bob".to_string()]];

            let lines = render_table(
                &headers,
                &alignments,
                &rows,
                &theme,
                false,
                false,
                None,
                None,
            );

            // Should have: top border, header, separator, 2 data rows, bottom border
            // Wrapping might add lines if text is tight, current implementation yields 7
            assert!(lines.len() >= 6);
        }

        #[test]
        fn test_multi_column_table() {
            let theme = test_theme();
            let headers = vec!["Name".to_string(), "Age".to_string(), "City".to_string()];
            let alignments = vec![Alignment::Left, Alignment::Right, Alignment::Center];
            let rows = vec![
                vec!["Alice".to_string(), "30".to_string(), "NYC".to_string()],
                vec!["Bob".to_string(), "25".to_string(), "LA".to_string()],
            ];

            let lines = render_table(
                &headers,
                &alignments,
                &rows,
                &theme,
                false,
                false,
                None,
                None,
            );

            // Should have at least 6 lines
            assert!(lines.len() >= 6);
        }

        #[test]
        fn test_selected_table_adds_arrow() {
            let theme = test_theme();
            let headers = vec!["Col".to_string()];
            let rows = vec![vec!["Data".to_string()]];

            let _lines_unselected =
                render_table(&headers, &[], &rows, &theme, false, false, None, None);
            let lines_selected =
                render_table(&headers, &[], &rows, &theme, true, false, None, None);

            // Selected table should have arrow prefix on first line
            let first_selected = &lines_selected[0];

            // Selected version should have "→ " at the start
            assert!(first_selected.spans.iter().any(|s| s.content.contains("")));
        }

        #[test]
        fn test_table_mode_shows_row_arrow() {
            let theme = test_theme();
            let headers = vec!["Col".to_string()];
            let rows = vec![vec!["Row1".to_string()], vec!["Row2".to_string()]];

            // Select cell at row 1, col 0
            let lines = render_table(&headers, &[], &rows, &theme, true, true, Some((1, 0)), None);

            // Find the row with the arrow
            assert!(
                lines
                    .iter()
                    .any(|l| l.spans.iter().any(|s| s.content.contains("")))
            );
        }

        #[test]
        fn test_header_only_table() {
            let theme = test_theme();
            let headers = vec!["Header1".to_string(), "Header2".to_string()];
            let alignments = vec![Alignment::Left, Alignment::Right];
            let rows: Vec<Vec<String>> = vec![];

            let lines = render_table(
                &headers,
                &alignments,
                &rows,
                &theme,
                false,
                false,
                None,
                None,
            );

            // Should have: top border, header, separator, bottom border = 4 lines
            assert_eq!(lines.len(), 4);
        }

        #[test]
        fn test_table_width_constraint() {
            let theme = test_theme();
            let headers = vec![
                "Very Long Header Name".to_string(),
                "Another Long Header".to_string(),
            ];
            let alignments = vec![Alignment::Left, Alignment::Left];
            let rows = vec![vec![
                "Some content here".to_string(),
                "More content".to_string(),
            ]];

            // Without width constraint
            let lines_unconstrained = render_table(
                &headers,
                &alignments,
                &rows,
                &theme,
                false,
                false,
                None,
                None,
            );

            // With width constraint - table will wrap
            let lines_constrained = render_table(
                &headers,
                &alignments,
                &rows,
                &theme,
                false,
                false,
                None,
                Some(40),
            );

            // Constrained version should have MORE lines due to wrapping
            assert!(lines_constrained.len() >= lines_unconstrained.len());
        }

        #[test]
        fn test_seven_column_table_at_width_146_no_panic() {
            // Regression test for crash when MIN_COL_WIDTH clamping pushes
            // total column width over budget after proportional shrink
            let theme = test_theme();
            let headers = vec![
                "Protocol".to_string(),
                "Port(s)".to_string(),
                "Transport".to_string(),
                "Purpose".to_string(),
                "Encryption".to_string(),
                "Key Feature".to_string(),
                "Common Usage".to_string(),
            ];
            let alignments = vec![Alignment::Left; 7];
            let rows = vec![
                vec![
                    "HTTP".to_string(),
                    "80".to_string(),
                    "TCP".to_string(),
                    "Web".to_string(),
                    "No".to_string(),
                    "Stateless".to_string(),
                    "Websites".to_string(),
                ],
                vec![
                    "HTTPS".to_string(),
                    "443".to_string(),
                    "TCP".to_string(),
                    "Secure Web".to_string(),
                    "TLS/SSL".to_string(),
                    "Encrypted HTTP".to_string(),
                    "Secure websites".to_string(),
                ],
                vec![
                    "FTP".to_string(),
                    "20/21".to_string(),
                    "TCP".to_string(),
                    "File Transfer".to_string(),
                    "Optional".to_string(),
                    "Active/Passive".to_string(),
                    "File sharing".to_string(),
                ],
            ];

            // Test specific widths around the previously crashing point
            for width in [30, 50, 80, 100, 130, 140, 145, 146, 147, 150, 160, 180, 200] {
                let lines = render_table(
                    &headers,
                    &alignments,
                    &rows,
                    &theme,
                    false,
                    false,
                    None,
                    Some(width),
                );
                assert!(!lines.is_empty(), "Table should render at width {}", width);
            }
        }
    }

    mod render_table_row_tests {
        use super::*;

        #[test]
        fn test_basic_row() {
            let theme = test_theme();
            let cells = vec!["A".to_string(), "B".to_string()];
            let col_widths = vec![5, 5];
            let alignments = vec![Alignment::Left, Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 0,
                is_header: false,
                in_table_mode: false,
                is_table_selected: false,
                selected_cell: None,
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);
            let line = &row_lines[0];

            // Should have spans for: │, cell1, │, cell2, │
            assert!(line.spans.len() >= 5);
        }

        #[test]
        fn test_header_row_styling() {
            let theme = test_theme();
            let cells = vec!["Header".to_string()];
            let col_widths = vec![10];
            let alignments = vec![Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 0,
                is_header: true,
                in_table_mode: false,
                is_table_selected: false,
                selected_cell: None,
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);
            let line = &row_lines[0];

            // Header should have bold modifier
            let cell_span = line.spans.iter().find(|s| s.content.contains("Header"));
            assert!(cell_span.is_some());
            assert!(
                cell_span
                    .unwrap()
                    .style
                    .add_modifier
                    .contains(Modifier::BOLD)
            );
        }

        #[test]
        fn test_selected_cell_highlighting() {
            let theme = test_theme();
            let cells = vec!["A".to_string(), "B".to_string()];
            let col_widths = vec![5, 5];
            let alignments = vec![Alignment::Left, Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 1,
                is_header: false,
                in_table_mode: true,
                is_table_selected: true,
                selected_cell: Some((1, 1)), // Select cell B
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);
            let line = &row_lines[0];

            // The selected cell should have a background color
            let cell_b_span = line.spans.iter().find(|s| s.content.contains("B"));
            assert!(cell_b_span.is_some());
            // Check it has the highlight background
            assert!(cell_b_span.unwrap().style.bg.is_some());
        }

        #[test]
        fn test_row_with_arrow_when_selected() {
            let theme = test_theme();
            let cells = vec!["Data".to_string()];
            let col_widths = vec![8];
            let alignments = vec![Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 1,
                is_header: false,
                in_table_mode: true,
                is_table_selected: true,
                selected_cell: Some((1, 0)),
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);
            let line = &row_lines[0];

            // Should have arrow at start when row is selected in table mode
            assert!(line.spans[0].content.contains(""));
        }

        #[test]
        fn test_row_wrapping() {
            let theme = test_theme();
            let cells = vec!["Very long text that should wrap".to_string()];
            let col_widths = vec![10]; // Small width will force wrapping
            let alignments = vec![Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 1,
                is_header: false,
                in_table_mode: false,
                is_table_selected: false,
                selected_cell: None,
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);

            // Should have multiple lines due to wrapping
            assert!(row_lines.len() > 1);
        }

        #[test]
        fn test_row_without_arrow_when_not_selected() {
            let theme = test_theme();
            let cells = vec!["Data".to_string()];
            let col_widths = vec![8];
            let alignments = vec![Alignment::Left];

            let ctx = TableRenderContext {
                theme: &theme,
                row_num: 2,
                is_header: false,
                in_table_mode: true,
                is_table_selected: true,
                selected_cell: Some((1, 0)), // Different row selected
            };

            let row_lines = render_table_row(&cells, &col_widths, &alignments, &ctx);
            let line = &row_lines[0];

            // Should have spaces, not arrow
            assert_eq!(line.spans[0].content, "  ");
        }
    }
}