frame 0.1.5

A markdown task tracker with a terminal UI for humans and a CLI for agents
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
use crate::util::unicode;
use unicode_segmentation::UnicodeSegmentation;

/// A single visual (screen) line produced by wrapping a logical line.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VisualLine {
    /// Index into the note's logical lines
    pub logical_line: usize,
    /// Byte offset within the logical line where this visual line starts
    pub byte_start: usize,
    /// Byte offset (exclusive) within the logical line where this visual line ends
    pub byte_end: usize,
    /// Byte offset within the logical line where this visual line starts (same as byte_start)
    pub char_start: usize,
    /// Byte offset (exclusive) within the logical line where this visual line ends (same as byte_end)
    pub char_end: usize,
    /// True for the first visual row of a logical line (gets a line number in gutter)
    pub is_first: bool,
}

/// A grapheme with its byte offset and display width.
struct Grapheme<'a> {
    s: &'a str,
    byte_offset: usize,
    display_width: usize,
}

/// Collect graphemes from a string with byte offsets and display widths.
fn graphemes(line: &str) -> Vec<Grapheme<'_>> {
    line.grapheme_indices(true)
        .map(|(i, g)| Grapheme {
            s: g,
            byte_offset: i,
            display_width: grapheme_display_width(g),
        })
        .collect()
}

fn grapheme_display_width(g: &str) -> usize {
    if g == "\t" {
        4
    } else {
        unicode_width::UnicodeWidthStr::width(g)
    }
}

/// Wrap a single logical line into visual lines.
///
/// Word boundary rules (priority order):
/// 1. Whitespace — break after space/tab
/// 2. After hyphens — break after `-`
/// 3. Character wrap — fallback if single token > width
///
/// Fill heuristic: if content before break < 50% of width, char-wrap inline
/// instead of pushing to next row.
pub fn wrap_line(line: &str, width: usize, logical_line: usize) -> Vec<VisualLine> {
    if width == 0 {
        return vec![VisualLine {
            logical_line,
            byte_start: 0,
            byte_end: line.len(),
            char_start: 0,
            char_end: line.len(),
            is_first: true,
        }];
    }

    let dw = unicode::display_width(line);
    if dw <= width {
        return vec![VisualLine {
            logical_line,
            byte_start: 0,
            byte_end: line.len(),
            char_start: 0,
            char_end: line.len(),
            is_first: true,
        }];
    }

    let gs = graphemes(line);
    let total = gs.len();

    let mut result = Vec::new();

    // Current visual line start (grapheme index)
    let mut vl_start: usize = 0;
    let mut col: usize = 0; // display column within current visual line

    let mut i: usize = 0; // grapheme index

    // Helper: byte offset at grapheme index (or line.len() if past end)
    let byte_at = |idx: usize| -> usize {
        if idx < gs.len() {
            gs[idx].byte_offset
        } else {
            line.len()
        }
    };

    while i < total {
        let token_start = i;
        let is_ws = gs[i].s.chars().all(|c| c.is_whitespace());

        if is_ws {
            while i < total && gs[i].s.chars().all(|c| c.is_whitespace()) {
                i += 1;
            }
        } else {
            while i < total && !gs[i].s.chars().all(|c| c.is_whitespace()) {
                let was_hyphen = gs[i].s == "-";
                i += 1;
                if was_hyphen && i < total && !gs[i].s.chars().all(|c| c.is_whitespace()) {
                    break;
                }
            }
        }

        let token_dw: usize = gs[token_start..i].iter().map(|g| g.display_width).sum();

        if col + token_dw <= width {
            col += token_dw;
        } else if col == 0 && !is_ws {
            // First token on line but too wide — grapheme-wrap it
            let mut placed_dw = 0;
            let mut j = token_start;
            while j < i {
                let gdw = gs[j].display_width;
                if placed_dw + gdw > width && placed_dw > 0 {
                    let be = byte_at(j);
                    let bs = byte_at(vl_start);
                    result.push(VisualLine {
                        logical_line,
                        byte_start: bs,
                        byte_end: be,
                        char_start: bs,
                        char_end: be,
                        is_first: result.is_empty(),
                    });
                    vl_start = j;
                    placed_dw = 0;
                }
                placed_dw += gdw;
                j += 1;
            }
            col = placed_dw;
        } else if is_ws {
            // Whitespace at wrap point — include as many whitespace chars as
            // fit on the current line, consume the rest. This keeps trailing
            // spaces at the end of VL0 so they remain in the byte range for
            // edit-mode cursor positioning.
            let remaining = width.saturating_sub(col);
            let mut j = token_start;
            let mut placed = 0;
            while j < i {
                let gdw = gs[j].display_width;
                if placed + gdw > remaining {
                    break;
                }
                placed += gdw;
                j += 1;
            }
            let bs = byte_at(vl_start);
            let be = byte_at(j);
            result.push(VisualLine {
                logical_line,
                byte_start: bs,
                byte_end: be,
                char_start: bs,
                char_end: be,
                is_first: result.is_empty(),
            });
            vl_start = i;
            col = 0;
        } else {
            // Word doesn't fit — check fill heuristic
            let remaining_space = width.saturating_sub(col);
            let blank_fraction = if width > 0 {
                remaining_space as f64 / width as f64
            } else {
                0.0
            };

            if blank_fraction > 0.5 && remaining_space > 0 {
                // Char-wrap inline: fill remaining space
                let mut placed = 0;
                let mut j = token_start;
                while j < i && placed + gs[j].display_width <= remaining_space {
                    placed += gs[j].display_width;
                    j += 1;
                }

                let bs = byte_at(vl_start);
                let be = byte_at(j);
                result.push(VisualLine {
                    logical_line,
                    byte_start: bs,
                    byte_end: be,
                    char_start: bs,
                    char_end: be,
                    is_first: result.is_empty(),
                });

                vl_start = j;
                col = 0;
                i = j;
            } else {
                // Word-wrap: emit current line, put this word on the next
                let bs = byte_at(vl_start);
                let be = byte_at(token_start);
                if token_start > vl_start {
                    result.push(VisualLine {
                        logical_line,
                        byte_start: bs,
                        byte_end: be,
                        char_start: bs,
                        char_end: be,
                        is_first: result.is_empty(),
                    });
                    vl_start = token_start;
                }
                col = token_dw;

                // If the token itself is wider than width, grapheme-wrap it
                if token_dw > width {
                    let mut placed_dw = 0;
                    let mut j = token_start;
                    while j < i {
                        let gdw = gs[j].display_width;
                        if placed_dw + gdw > width && placed_dw > 0 {
                            let vbs = byte_at(vl_start);
                            let vbe = byte_at(j);
                            result.push(VisualLine {
                                logical_line,
                                byte_start: vbs,
                                byte_end: vbe,
                                char_start: vbs,
                                char_end: vbe,
                                is_first: result.is_empty(),
                            });
                            vl_start = j;
                            placed_dw = 0;
                        }
                        placed_dw += gdw;
                        j += 1;
                    }
                    col = placed_dw;
                }
            }
        }
    }

    // Emit final visual line
    let bs = byte_at(vl_start);
    result.push(VisualLine {
        logical_line,
        byte_start: bs,
        byte_end: line.len(),
        char_start: bs,
        char_end: line.len(),
        is_first: result.is_empty(),
    });

    result
}

/// Wrap multiple logical lines, returning all visual lines in order.
pub fn wrap_lines(lines: &[&str], width: usize) -> Vec<VisualLine> {
    let mut result = Vec::new();
    for (idx, line) in lines.iter().enumerate() {
        result.extend(wrap_line(line, width, idx));
    }
    result
}

/// Wrap lines for edit mode with two adjustments over [`wrap_lines`]:
///
/// 1. Consumed whitespace at wrap points is included at the start of the
///    next visual line so that trailing spaces are visible and the cursor
///    can be positioned on them.
/// 2. An extra empty visual line is inserted when the cursor would be
///    rendered past the right edge of a full-width visual line.
pub fn wrap_lines_for_edit(
    lines: &[&str],
    width: usize,
    cursor_line: usize,
    cursor_col: usize,
) -> Vec<VisualLine> {
    let mut vls = wrap_lines(lines, width);
    if width == 0 {
        return vls;
    }

    // Fill gaps between consecutive visual lines of the same logical line.
    // The wrapping algorithm consumes whitespace at wrap points, leaving a
    // gap (prev.byte_end < next.byte_start). Extending byte_start backwards
    // makes the whitespace part of the next visual line.
    for i in 1..vls.len() {
        if vls[i].logical_line == vls[i - 1].logical_line && vls[i].byte_start > vls[i - 1].byte_end
        {
            vls[i].byte_start = vls[i - 1].byte_end;
            vls[i].char_start = vls[i - 1].char_end;
        }
    }

    // Add an extra visual line when the cursor is at the end of a visual
    // line whose content fills the full width, so the cursor block doesn't
    // render off-screen.
    let cursor_vrow = logical_to_visual_row(&vls, cursor_line, cursor_col);
    if let Some(vl) = vls.get(cursor_vrow)
        && cursor_col >= vl.char_end
    {
        let line_text = lines.get(vl.logical_line).copied().unwrap_or("");
        let slice = &line_text[vl.byte_start..vl.byte_end];
        let slice_width = unicode::display_width(slice);
        if slice_width >= width {
            let extra = VisualLine {
                logical_line: vl.logical_line,
                byte_start: vl.byte_end,
                byte_end: vl.byte_end,
                char_start: vl.byte_end,
                char_end: vl.byte_end,
                is_first: false,
            };
            vls.insert(cursor_vrow + 1, extra);
        }
    }

    vls
}

/// Compute the gutter width for line numbers: max(1, digits(line_count)) + 1.
/// Minimum gutter is 3 (2 digits + 1 space).
pub fn gutter_width(line_count: usize) -> usize {
    let digits = if line_count == 0 {
        1
    } else {
        line_count.to_string().len()
    };
    (digits + 1).max(3)
}

/// Map a logical cursor position (line, col_byte_offset) to a visual row index
/// within the given visual lines. `col` is a byte offset within the logical line.
pub fn logical_to_visual_row(visual_lines: &[VisualLine], line: usize, col: usize) -> usize {
    for (i, vl) in visual_lines.iter().enumerate() {
        if vl.logical_line == line {
            if col < vl.byte_end || (col == vl.byte_end && i + 1 >= visual_lines.len()) {
                return i;
            }
            // Check if this is the last visual row for this logical line
            let next_is_same = visual_lines
                .get(i + 1)
                .is_some_and(|next| next.logical_line == line);
            if col >= vl.byte_start && !next_is_same {
                return i;
            }
        }
    }
    visual_lines.len().saturating_sub(1)
}

/// Map a visual row index back to a logical cursor position (line, byte_offset).
/// `target_visual_col` is the desired display column (terminal cells) within the visual row.
pub fn visual_row_to_logical(
    visual_lines: &[VisualLine],
    row: usize,
    target_visual_col: usize,
    lines: &[&str],
) -> (usize, usize) {
    if let Some(vl) = visual_lines.get(row) {
        let logical_line = vl.logical_line;
        let line_str = lines.get(logical_line).copied().unwrap_or("");
        let vl_text = &line_str[vl.byte_start..vl.byte_end];
        let byte_within_vl = unicode::display_col_to_byte_offset(vl_text, target_visual_col);
        let col = vl.byte_start + byte_within_vl;
        (logical_line, col.min(vl.byte_end))
    } else {
        (0, 0)
    }
}

/// Compute the visual column (display cells) of a logical cursor within its visual row.
/// `col` is a byte offset within the logical line.
pub fn logical_to_visual_col(
    visual_lines: &[VisualLine],
    line: usize,
    col: usize,
    lines: &[&str],
) -> usize {
    let row = logical_to_visual_row(visual_lines, line, col);
    if let Some(vl) = visual_lines.get(row) {
        let logical_line_str = lines.get(vl.logical_line).copied().unwrap_or("");
        let byte_start = vl.byte_start;
        let byte_cursor = col.min(vl.byte_end);
        let within_vl = &logical_line_str[byte_start..byte_cursor];
        unicode::display_width(within_vl)
    } else {
        0
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn no_wrap_needed() {
        let vls = wrap_line("hello world", 80, 0);
        assert_eq!(vls.len(), 1);
        assert_eq!(vls[0].byte_start, 0);
        assert_eq!(vls[0].byte_end, 11);
        assert!(vls[0].is_first);
    }

    #[test]
    fn wrap_at_space() {
        // "hello world" with width 7: "hello " fits (6 cells), then "world" wraps
        let vls = wrap_line("hello world", 7, 0);
        assert_eq!(vls.len(), 2);
        assert_eq!(vls[0].byte_start, 0);
        assert!(vls[0].is_first);
        assert_eq!(vls[1].logical_line, 0);
        assert!(!vls[1].is_first);
        let second = &"hello world"[vls[1].byte_start..vls[1].byte_end];
        assert_eq!(second, "world");
    }

    #[test]
    fn wrap_at_hyphen() {
        let vls = wrap_line("long-word here", 6, 0);
        assert!(vls.len() >= 2);
        assert_eq!(vls[0].byte_end, 5); // "long-"
    }

    #[test]
    fn char_wrap_long_word() {
        let vls = wrap_line("abcdefghij", 4, 0);
        assert!(vls.len() >= 2);
        for vl in &vls {
            let text = &"abcdefghij"[vl.byte_start..vl.byte_end];
            assert!(unicode::display_width(text) <= 4);
        }
    }

    #[test]
    fn empty_line() {
        let vls = wrap_line("", 80, 0);
        assert_eq!(vls.len(), 1);
        assert_eq!(vls[0].byte_start, 0);
        assert_eq!(vls[0].byte_end, 0);
        assert!(vls[0].is_first);
    }

    #[test]
    fn zero_width() {
        let vls = wrap_line("hello", 0, 0);
        assert_eq!(vls.len(), 1);
    }

    #[test]
    fn wrap_lines_multiple() {
        let lines = vec!["hello world", "foo"];
        let vls = wrap_lines(&lines, 6);
        assert!(vls.len() >= 3);
        assert_eq!(vls[0].logical_line, 0);
        assert_eq!(vls.last().unwrap().logical_line, 1);
    }

    #[test]
    fn gutter_width_small() {
        assert_eq!(gutter_width(1), 3);
        assert_eq!(gutter_width(9), 3);
        assert_eq!(gutter_width(10), 3);
        assert_eq!(gutter_width(99), 3);
        assert_eq!(gutter_width(100), 4);
    }

    #[test]
    fn logical_to_visual_roundtrip() {
        let text = "hello world foo bar";
        let lines = vec![text];
        let vls = wrap_line(text, 6, 0);
        let row = logical_to_visual_row(&vls, 0, 0);
        assert_eq!(row, 0);
        let (line, col) = visual_row_to_logical(&vls, row, 0, &lines);
        assert_eq!(line, 0);
        assert_eq!(col, 0);
    }

    #[test]
    fn fill_heuristic_50_percent() {
        let vls = wrap_line("abcd xxxxxxxxxx", 10, 0);
        assert!(vls.len() >= 2);
    }

    #[test]
    fn tab_counts_as_four() {
        let vls = wrap_line("\thello", 10, 0);
        assert_eq!(vls.len(), 1);

        let vls = wrap_line("\thello", 8, 0);
        assert!(vls.len() >= 2);
    }

    #[test]
    fn visual_col_computation() {
        let text = "hello world";
        let lines = vec![text];
        let vls = wrap_line(text, 6, 0);
        // "hello" is visual row 0, "world" is visual row 1
        // cursor at byte 6 (w of "world") should be visual col 0 on row 1
        let vcol = logical_to_visual_col(&vls, 0, 6, &lines);
        assert_eq!(vcol, 0);
        // cursor at byte 8 should be visual col 2 on row 1
        let vcol = logical_to_visual_col(&vls, 0, 8, &lines);
        assert_eq!(vcol, 2);
    }

    #[test]
    fn wrap_cjk() {
        // "你好世界" = 8 display cells
        let vls = wrap_line("你好世界", 5, 0);
        assert_eq!(vls.len(), 2);
        // First visual line: "你好" (4 cells)
        let first = &"你好世界"[vls[0].byte_start..vls[0].byte_end];
        assert_eq!(first, "你好");
    }

    #[test]
    fn wrap_emoji() {
        let s = "🎉🚀💫✨";
        // Each emoji is 2 cells, total 8 cells
        let vls = wrap_line(s, 5, 0);
        assert_eq!(vls.len(), 2);
        let first = &s[vls[0].byte_start..vls[0].byte_end];
        assert_eq!(unicode::display_width(first), 4); // 🎉🚀
    }

    #[test]
    fn wrap_never_breaks_grapheme() {
        // Combining character must never be separated from its base
        let s = "cafe\u{0301} is good"; // "café is good"
        let vls = wrap_line(s, 6, 0);
        for vl in &vls {
            let text = &s[vl.byte_start..vl.byte_end];
            // No visual line should start with a combining character
            if let Some(first_char) = text.chars().next() {
                assert!(
                    unicode_width::UnicodeWidthChar::width(first_char) != Some(0)
                        || first_char == '\u{0301}' && text.starts_with("e\u{0301}"),
                    "Line starts with zero-width character: {:?}",
                    text
                );
            }
        }
    }

    #[test]
    fn edit_cursor_at_full_width_line_end() {
        // Cursor at end of a line that exactly fills the width should get an extra VL
        let lines = vec!["abcdefghij"];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 10);
        assert_eq!(vls.len(), 2);
        assert_eq!(vls[1].byte_start, 10);
        assert_eq!(vls[1].byte_end, 10);
        assert!(!vls[1].is_first);
        // Cursor should be on the extra visual row
        let row = logical_to_visual_row(&vls, 0, 10);
        assert_eq!(row, 1);
    }

    #[test]
    fn edit_cursor_mid_line_no_extra_vl() {
        // Cursor in the middle of a line should not add an extra VL
        let lines = vec!["abcdefghij"];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 5);
        assert_eq!(vls.len(), 1);
    }

    #[test]
    fn edit_cursor_at_short_line_end_no_extra_vl() {
        // Cursor at the end of a line that doesn't fill the width should not add an extra VL
        let lines = vec!["hello"];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 5);
        assert_eq!(vls.len(), 1);
    }

    #[test]
    fn edit_cursor_at_end_of_wrapped_full_width_row() {
        // Cursor at end of second visual row that also fills the width
        let lines = vec!["abcdefghijklmnopqrst"];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 20);
        // Should be 3 VLs: two wrapping rows + one extra for cursor
        assert_eq!(vls.len(), 3);
        let row = logical_to_visual_row(&vls, 0, 20);
        assert_eq!(row, 2);
    }

    #[test]
    fn edit_cursor_on_consumed_whitespace() {
        // Cursor on a space consumed by wrapping should end up on the next VL
        // without an extra VL being added
        let lines = vec!["abcdefghij k"];
        let vls_no_edit = wrap_lines(&lines, 10);
        let vls = wrap_lines_for_edit(&lines, 10, 0, 10);
        // No extra VL should be inserted
        assert_eq!(vls.len(), vls_no_edit.len());
        // But the gap should be filled: the space is now part of VL1
        assert_eq!(vls[1].byte_start, 10);
        let text = &"abcdefghij k"[vls[1].byte_start..vls[1].byte_end];
        assert_eq!(text, " k");
    }

    #[test]
    fn edit_trailing_spaces_visible() {
        // Trailing spaces at the wrap boundary should be visible in the next VL
        let lines = vec!["abcdefghij   "];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 13);
        assert_eq!(vls.len(), 2);
        // VL1 should contain the 3 trailing spaces
        let text = &"abcdefghij   "[vls[1].byte_start..vls[1].byte_end];
        assert_eq!(text, "   ");
    }

    #[test]
    fn edit_space_cursor_advances() {
        // Typing a space at the wrap boundary should move the cursor forward
        let lines = vec!["abcdefghij "];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 11);
        // Cursor at byte 11 (after the space) should be on VL1
        let row = logical_to_visual_row(&vls, 0, 11);
        assert_eq!(row, 1);
        // Visual column should be 1 (past the space)
        let vcol = logical_to_visual_col(&vls, 0, 11, &lines);
        assert_eq!(vcol, 1);
    }

    #[test]
    fn edit_space_cursor_no_skip() {
        // Typing consecutive spaces at the wrap boundary should advance
        // the cursor by exactly 1 position each time (no column skip).
        // width=10, line "abcdefghi" (9 chars)

        // After 1st space: "abcdefghi " fills width, cursor wraps to row 1 col 0
        let lines1 = vec!["abcdefghi "];
        let vls1 = wrap_lines_for_edit(&lines1, 10, 0, 10);
        let vcol1 = logical_to_visual_col(&vls1, 0, 10, &lines1);
        assert_eq!(vcol1, 0); // cursor at start of extra row

        // After 2nd space: "abcdefghi  " wraps, first space stays on line 1
        let lines2 = vec!["abcdefghi  "];
        let vls2 = wrap_lines_for_edit(&lines2, 10, 0, 11);
        let vcol2 = logical_to_visual_col(&vls2, 0, 11, &lines2);
        assert_eq!(vcol2, 1); // cursor advanced by 1, not 2
    }

    #[test]
    fn edit_no_gap_fill_across_logical_lines() {
        // Gap fill should not cross logical line boundaries
        let lines = vec!["abcdefghij", "hello"];
        let vls = wrap_lines_for_edit(&lines, 10, 0, 0);
        // VL0 is logical line 0, VL1 is logical line 1 — no gap fill
        assert_eq!(vls[0].logical_line, 0);
        assert_eq!(vls[1].logical_line, 1);
        assert_eq!(vls[1].byte_start, 0);
    }
}