mahbot 0.11.2

An autonomous agentic engineering system that manages software development through role separation, subagents, and deterministic diagnostics.
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
//! Editor widget tests: buffer, cursor, selection and rendering primitives.

use super::*;

#[test]
fn test_insert_paste_enter_cases() {
    use super::EditorAction::*;
    let cases = [
        (
            "insert_character",
            Insert('l'),
            "helo",
            (0, 2),
            "hello",
            None,
        ),
        (
            "insert_at_end",
            Insert('!'),
            "hello",
            (0, 5),
            "hello!",
            None,
        ),
        ("paste", Paste("ll".into()), "heo", (0, 2), "hello", None),
        (
            "enter",
            Enter,
            "hello world",
            (0, 5),
            "hello\n world",
            Some((1, 0)),
        ),
        (
            "multi_byte_character",
            Insert('é'),
            "héllo",
            (0, 1),
            "hééllo",
            Some((0, 2)),
        ),
    ];
    for &(name, ref action, input, (line, col), expected, expected_cursor) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(line, col);
        buf.perform_action(action.clone());
        assert_eq!(buf.text(), expected, "case {name}: text");
        if let Some((line, col)) = expected_cursor {
            let cursor = buf.cursor();
            assert_eq!(cursor.line, line, "case {name}: line");
            assert_eq!(cursor.column, col, "case {name}: col");
        }
    }

    let cases = [
        (
            "insert_with_selection_replaces",
            Insert('X'),
            "hello world",
            (0, 0),
            None,
            true,
            "X",
        ),
        (
            "paste_with_selection_replaces",
            Paste("there".into()),
            "hello world",
            (0, 6),
            Some((0, 11)),
            false,
            "hello there",
        ),
        (
            "enter_with_selection_replaces",
            Enter,
            "hello",
            (0, 3),
            Some((0, 5)),
            false,
            "hel\n",
        ),
    ];
    for &(name, ref action, input, (line, col), select_to, select_all, expected) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(line, col);
        if select_all {
            buf.select_all();
        }
        if let Some((line, col)) = select_to {
            buf.perform_action(SelectTo { line, col });
        }
        buf.perform_action(action.clone());
        assert_eq!(buf.text(), expected, "case {name}: text");
    }
}

#[test]
fn test_enter_at_end_of_highlighted_file_with_trailing_newline() {
    // Regression: Enter at the end of a highlighted file that *has* a trailing newline must place
    // the cursor on a new blank line, not at the start of the last content line.
    let buf = EditorBuffer::with_text("fn main() {}\n", Some(HighlightLanguage::Rust));
    assert_eq!(buf.line_count(), 2);
    let cursor_before = buf.cursor();
    assert_eq!(cursor_before.line, 0);
    assert_eq!(cursor_before.column, 0);
    let content_len = "fn main() {}".chars().count();
    buf.move_to(0, content_len);
    buf.perform_action(EditorAction::Enter);
    assert_eq!(buf.text(), "fn main() {}\n\n");
    let cursor = buf.cursor();
    assert_eq!(cursor.line, 1);
    assert_eq!(cursor.column, 0);
}

#[test]
fn test_enter_at_end_of_highlighted_file_no_trailing_newline() {
    // Same as above but with *no* trailing newline — the bug would clamp the cursor to (line=0,
    // col=0).
    let buf = EditorBuffer::with_text("fn main() {}", Some(HighlightLanguage::Rust));
    assert_eq!(buf.line_count(), 1);
    let content_len = "fn main() {}".chars().count();
    buf.move_to(0, content_len);
    buf.perform_action(EditorAction::Enter);
    assert_eq!(buf.text(), "fn main() {}\n");
    let cursor = buf.cursor();
    assert_eq!(cursor.line, 1);
    assert_eq!(cursor.column, 0);
}

#[test]
fn test_backspace_delete_cases() {
    let cases = [
        ("backspace", "hello", Some((0, 5)), "hell", Some((0, 4))),
        ("backspace_at_start", "hello", None, "hello", None),
        (
            "backspace_newline",
            "hello\nworld",
            Some((1, 0)),
            "helloworld",
            Some((0, 5)),
        ),
    ];
    for &(name, input, cursor_pos, expected, expected_cursor) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        if let Some((line, col)) = cursor_pos {
            buf.move_to(line, col);
        }
        buf.perform_action(EditorAction::Backspace);
        assert_eq!(buf.text(), expected, "case {name}: text");
        if let Some((line, col)) = expected_cursor {
            let cursor = buf.cursor();
            assert_eq!(cursor.line, line, "case {name}: line");
            assert_eq!(cursor.column, col, "case {name}: col");
        }
    }

    let cases = [
        ("delete", "hello", None, "ello"),
        ("delete_at_end", "hello", Some((0, 5)), "hello"),
        ("delete_cafe", "café", Some((0, 3)), "caf"),
        ("delete_cyrillic", "привет", Some((0, 0)), "ривет"),
        // Editor tracks scalar-value columns, not full grapheme clusters.
        ("delete_emoji", "a🎉b", Some((0, 1)), "ab"),
    ];
    for &(name, input, cursor_pos, expected) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        if let Some((line, col)) = cursor_pos {
            buf.move_to(line, col);
        }
        buf.perform_action(EditorAction::Delete);
        assert_eq!(buf.text(), expected, "case {name}: text");
    }
}

#[test]
fn test_char_col_to_byte_offset_multibyte() {
    let line = "héllo";
    assert_eq!(char_col_to_byte_offset_in_line(line, 0), 0);
    assert_eq!(char_col_to_byte_offset_in_line(line, 1), 1);
    assert_eq!(char_col_to_byte_offset_in_line(line, 2), 3);
    assert_eq!(char_col_to_byte_range_in_line(line, 1), (1, 3));
}

#[test]
fn test_multiline_indent_preserves_selection() {
    let buf = EditorBuffer::with_text("- item one\n- item two\n- item three", None);
    buf.move_to(0, 0);
    buf.perform_action(EditorAction::SelectTo { line: 1, col: 100 });
    assert!(buf.cursor().selection.is_some());

    buf.perform_action(EditorAction::Indent);
    assert_eq!(buf.text(), "\t- item one\n\t- item two\n- item three");
    assert!(
        buf.cursor().selection.is_some(),
        "selection should survive first indent"
    );
    assert_eq!(
        buf.selection(),
        Some("\t- item one\n\t- item two".to_string())
    );

    buf.perform_action(EditorAction::Indent);
    assert_eq!(buf.text(), "\t\t- item one\n\t\t- item two\n- item three");
    assert!(
        buf.cursor().selection.is_some(),
        "selection should survive second indent"
    );

    buf.perform_action(EditorAction::Unindent);
    assert_eq!(buf.text(), "\t- item one\n\t- item two\n- item three");
    assert!(
        buf.cursor().selection.is_some(),
        "selection should survive unindent"
    );
}

#[test]
fn test_line_col_roundtrip() {
    let text = "hello\nworld\nfoo";
    for (line, line_text) in text.lines().enumerate() {
        for (col, _) in line_text.chars().enumerate() {
            let offset = line_col_to_byte_offset(text, line, col);
            let (rl, rc) = byte_offset_to_line_col(text, offset);
            assert_eq!(rl, line, "line mismatch at ({line},{col})");
            assert_eq!(rc, col, "col mismatch at ({line},{col})");
        }
        let col = line_text.chars().count();
        let offset = line_col_to_byte_offset(text, line, col);
        let (rl, rc) = byte_offset_to_line_col(text, offset);
        assert_eq!(rl, line, "line mismatch at end of line {line}");
        assert_eq!(rc, col, "col mismatch at end of line {line}");
    }
}

#[test]
fn test_selection_normalization_cases() {
    type Setup = fn(&EditorBuffer);
    let cases = [
        (
            "shift_left_at_bof_no_selection",
            "hello",
            (|buf| {
                buf.perform_action(EditorAction::Move {
                    direction: CursorMove::Left,
                    select: true,
                });
            }) as Setup,
            (0, 0),
            None,
        ),
        (
            "shift_right_then_back_collapses_selection",
            "hello",
            (|buf| {
                buf.move_to(0, 0);
                buf.perform_action(EditorAction::Move {
                    direction: CursorMove::Right,
                    select: true,
                });
                buf.perform_action(EditorAction::Move {
                    direction: CursorMove::Left,
                    select: true,
                });
            }) as Setup,
            (0, 0),
            None,
        ),
        (
            "select_to_then_move_clears_selection",
            "abcdef",
            (|buf| {
                buf.move_to(0, 1);
                buf.perform_action(EditorAction::SelectTo { line: 0, col: 4 });
                assert_eq!(
                    buf.selection(),
                    Some("bcd".to_string()),
                    "case select_to_then_move_clears_selection (selection before move)"
                );
                buf.move_to(0, 0);
            }) as Setup,
            (0, 0),
            None,
        ),
    ];
    for &(name, text, setup, (line, col), selection) in &cases {
        let buf = EditorBuffer::with_text(text, None);
        setup(&buf);
        let cursor = buf.cursor();
        assert_eq!(cursor.line, line, "case {name}: line");
        assert_eq!(cursor.column, col, "case {name}: col");
        assert_eq!(
            buf.selection(),
            selection.map(str::to_string),
            "case {name}: selection"
        );
    }
}

#[test]
fn test_toggle_line_comment() {
    use super::highlight::HighlightLanguage::*;
    let cases = [
        ("add", "hello", "// hello", 0),
        ("remove", "// hello", "hello", 0),
        ("remove_with_space", "//  hello", " hello", 0),
        ("preserves_whitespace", "    hello", "    // hello", 0),
        (
            "preserves_neighbor_lines",
            "first\nsecond\nthird",
            "first\n// second\nthird",
            1,
        ),
    ];
    for &(name, input, expected, cursor_line) in &cases {
        let buf = EditorBuffer::with_text(input, Some(Rust));
        if cursor_line != 0 {
            buf.move_to(cursor_line, 0);
        }
        buf.perform_action(EditorAction::ToggleLineComment);
        assert_eq!(buf.text(), expected, "case {name}: text");
    }

    let cases = [
        ("noop_unknown", "hello", "hello", None, None),
        ("rust_hash", "hello", "# hello", Some(Python), None),
        ("yaml_via_extension", "hello", "# hello", None, Some("yaml")),
        (
            "unknown_extension_noop",
            "hello",
            "hello",
            None,
            Some("xyz"),
        ),
    ];
    for &(name, input, expected, language, file_ext) in &cases {
        let buf = EditorBuffer::with_text(input, language);
        if let Some(ext) = file_ext {
            buf.set_file_extension(Some(ext));
        }
        buf.perform_action(EditorAction::ToggleLineComment);
        assert_eq!(buf.text(), expected, "case {name}: text");
    }
}

#[test]
fn test_jump_to_matching_bracket() {
    let cases = [
        ("forward_paren", "(hello)", 1, 0, 6),
        ("backward_paren", "(hello)", 6, 0, 1),
        ("square_bracket", "[hello]", 1, 0, 6),
        ("brace", "{hello}", 1, 0, 6),
        ("none", "hello", 3, 0, 3),
    ];
    for &(name, input, cursor_col, expected_line, expected_col) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(0, cursor_col);
        buf.perform_action(EditorAction::JumpToMatchingBracket);
        let cursor = buf.cursor();
        assert_eq!(cursor.line, expected_line, "case {name}: line");
        assert_eq!(cursor.column, expected_col, "case {name}: col");
    }
}

#[test]
fn test_delete_line_cases() {
    let lines = "line1\nline2\nline3";
    let cases = [
        ("current_line", lines, 1, None, "line1\nline3"),
        ("first_line", lines, 0, None, "line2\nline3"),
        ("last_line", lines, 2, None, "line1\nline2"),
        ("single_line", "hello", 0, None, ""),
        ("selected_lines", "a\nb\nc\nd\ne", 1, Some((3, 0)), "a\ne"),
    ];
    for &(name, input, cursor_line, select_to, expected) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(cursor_line, 0);
        if let Some((line, col)) = select_to {
            buf.perform_action(EditorAction::SelectTo { line, col });
        }
        buf.perform_action(EditorAction::DeleteLine);
        assert_eq!(buf.text(), expected, "case {name}: text");
        let cursor = buf.cursor();
        let line = cursor_line.min(expected.split('\n').count() - 1);
        assert_eq!(cursor.line, line, "case {name}: line");
        assert_eq!(cursor.column, 0, "case {name}: col");
    }
}

#[test]
fn test_duplicate_line_cases() {
    let lines = "hello\nworld";
    let cases = [
        ("current_line", lines, 0, None, "hello\nhello\nworld"),
        ("last_line", lines, 1, None, "hello\nworld\nworld"),
        (
            "selected_lines",
            "a\nb\nc\nd",
            1,
            Some((2, 0)),
            "a\nb\nc\nb\nc\nd",
        ),
    ];
    for &(name, input, cursor_line, select_to, expected) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(cursor_line, 0);
        if let Some((line, col)) = select_to {
            buf.perform_action(EditorAction::SelectTo { line, col });
        }
        buf.perform_action(EditorAction::DuplicateLine);
        assert_eq!(buf.text(), expected, "case {name}: text");
        // The cursor lands on the last line of the duplicated block, at column 0.
        let duplicated = select_to.map_or(1, |(end, _)| end - cursor_line + 1);
        let cursor = buf.cursor();
        assert_eq!(cursor.line, cursor_line + duplicated, "case {name}: line");
        assert_eq!(cursor.column, 0, "case {name}: col");
    }
}

#[test]
fn test_move_line_cases() {
    use super::EditorAction::*;
    let cases = [
        ("up", MoveLineUp, "a\nb\nc", 1, None, "b\na\nc", Some(0)),
        ("down", MoveLineDown, "a\nb\nc", 1, None, "a\nc\nb", Some(2)),
        ("up_at_top", MoveLineUp, "a\nb", 0, None, "a\nb", None),
        (
            "down_at_bottom",
            MoveLineDown,
            "a\nb",
            1,
            None,
            "a\nb",
            None,
        ),
        (
            "selected_down",
            MoveLineDown,
            "a\nb\nc\nd",
            1,
            Some((2, 0)),
            "a\nd\nb\nc",
            Some(2),
        ),
    ];
    for &(name, ref action, input, cursor_line, select_to, expected, expected_line) in &cases {
        let buf = EditorBuffer::with_text(input, None);
        buf.move_to(cursor_line, 0);
        if let Some((line, col)) = select_to {
            buf.perform_action(SelectTo { line, col });
        }
        buf.perform_action(action.clone());
        assert_eq!(buf.text(), expected, "case {name}: text");
        if let Some(line) = expected_line {
            let cursor = buf.cursor();
            assert_eq!(cursor.line, line, "case {name}: line");
            assert_eq!(cursor.column, 0, "case {name}: col");
        }
    }
}

#[test]
fn test_has_trailing_newline_and_detect_line_ending() {
    assert!(has_trailing_newline("hello\n"));
    assert!(!has_trailing_newline("hello"));
    assert!(!has_trailing_newline(""));
    assert_eq!(detect_line_ending("hello\nworld\n"), LineEnding::Lf);
    assert_eq!(detect_line_ending("hello\r\nworld\r\n"), LineEnding::Crlf);
}

#[test]
fn test_line_helpers_preserve_crlf_on_move_down() {
    let text = "a\r\nb\r\nc";
    let mut lines = logical_lines(text);
    swap_lines_with_endings(&mut lines, 1, 2);
    fix_line_endings(
        &mut lines,
        has_trailing_newline(text),
        detect_line_ending(text),
    );
    assert_eq!(reassemble_lines(&lines), "a\r\nc\r\nb");
}

#[test]
fn test_line_helpers_preserve_trailing_blank_line() {
    let text = "line one\nline two\n\n";
    let lines = logical_lines(text);
    assert_eq!(lines[2].0, "");
    assert_eq!(lines[2].1, "\n");
    assert_eq!(reassemble_lines(&lines), text);
}

#[test]
fn test_select_to_duplicate_endpoint_cases() {
    let cases = [
        ("duplicate_endpoint", "hello world", 0, 5, "hello"),
        ("same_endpoint", "hello", 2, 3, "l"),
    ];
    for &(name, text, start_col, end_col, expected) in &cases {
        let buf = EditorBuffer::with_text(text, None);
        buf.move_to(0, start_col);
        buf.perform_action(EditorAction::SelectTo {
            line: 0,
            col: end_col,
        });
        assert!(
            buf.cursor().selection.is_some(),
            "case {name}: first SelectTo"
        );
        // Repeated SelectTo at the drag endpoint (duplicate CursorMoved) must not collapse an
        // existing selection.
        buf.perform_action(EditorAction::SelectTo {
            line: 0,
            col: end_col,
        });
        assert_eq!(
            buf.selection(),
            Some(expected.to_string()),
            "case {name}: duplicate SelectTo"
        );
    }
}

#[test]
fn test_input_method_preedit_reported() {
    let buf = EditorBuffer::with_text("", None);
    let widget = EditorWidget::new(&buf);
    let state = EditorWidgetState {
        preedit: Some(input_method::Preedit {
            content: "你好".to_string(),
            selection: Some(1..2),
            text_size: None,
        }),
        ..EditorWidgetState::default()
    };
    let bounds = Rectangle::new(Point::ORIGIN, Size::new(200.0, 200.0));
    let ime = widget.input_method(&state, bounds);
    assert!(ime.to_owned().is_enabled());
    match ime {
        input_method::InputMethod::Enabled {
            preedit: Some(p), ..
        } => {
            assert_eq!(p.content, "你好");
            assert_eq!(p.selection, Some(1..2));
        }
        other => panic!("expected Enabled with preedit, got {other:?}"),
    }
}

#[test]
fn test_cursor_rect_selection_anchor() {
    let buf = EditorBuffer::with_text("hello\nworld", None);
    // Cursor at (1,4), selection anchor at (0,3) — reversed, so the IME must anchor at the
    // selection start.
    buf.move_to(0, 3);
    buf.perform_action(EditorAction::SelectTo { line: 1, col: 4 });
    let buffer = with_font_system(|font_sys| {
        let mut b = buf.borrow_buffer_mut();
        reshape_and_shape(&mut b, font_sys, Some(0.0), 0.0, 200.0, 200.0);
        b.clone()
    });
    let geo = TextGeometry {
        clip: Rectangle::new(Point::ORIGIN, Size::new(200.0, 200.0)),
        x: 8.0,
        y: 8.0,
    };
    let rect = ime_caret_rect(&buffer, &geo, &buf);
    let expected = cursor_rect(&buffer, &geo, 0, 3, geo.x);
    assert_eq!(rect, expected);
    assert!(rect.y < cursor_rect(&buffer, &geo, 1, 4, geo.x).y);
}

#[test]
fn test_masked_render_buffer_builds_dots_without_reborrow() {
    // Regression for the Settings-page panic: `layout()` called `self.buffer.text()` (re-borrowing
    // the RefCell via `borrow()`) while the `borrow_buffer_mut()` RefMut was held, panicking on the
    // masked (password) path with "already mutably borrowed". The masked render path must derive
    // the text from the already-held RefMut.
    let buf = EditorBuffer::with_text("secret\npassword", None);
    let mbuffer = with_font_system(|font_sys| {
        let buffer = buf.borrow_buffer_mut();
        let mb = build_masked_render_buffer(font_sys, &buffer, false, 0.0, 0.0, 300.0, 100.0);
        assert_eq!(buffer_text(&buffer), "secret\npassword");
        mb
    });
    assert_eq!(buffer_text(&mbuffer), "••••••\n••••••••");
}

#[test]
fn test_masked_render_buffer_single_line_does_not_wrap() {
    // Password fields are single-line: the masked dots must not wrap (matching the real single-line
    // layout) — this is the exact widget configuration that triggered the original panic.
    let buf = EditorBuffer::with_text("hunter2", None);
    let mbuffer = with_font_system(|font_sys| {
        let buffer = buf.borrow_buffer_mut();
        build_masked_render_buffer(font_sys, &buffer, true, 0.0, 0.0, 100.0, 30.0)
    });
    assert_eq!(buffer_text(&mbuffer), "•••••••");
}

#[test]
fn test_cursor_follows_focus_state() {
    let buf = EditorBuffer::with_text("", None);
    let field = EditorWidget::new(&buf).single_line(true).id("field");
    let state = EditorWidgetState::default();
    assert!(!field.should_draw_cursor(&state));
    let focused = EditorWidgetState {
        is_focused: true,
        ..EditorWidgetState::default()
    };
    assert!(field.should_draw_cursor(&focused));
    // Masked fields still show the caret when focused (the IME `is_active_surface` predicate would
    // suppress them, but the caret must not be).
    let masked = EditorWidget::new(&buf)
        .single_line(true)
        .masked(true)
        .id("pw");
    assert!(masked.should_draw_cursor(&focused));
    let blurred = EditorWidgetState {
        is_focused: true,
        is_window_focused: false,
        ..EditorWidgetState::default()
    };
    assert!(!field.should_draw_cursor(&blurred));
    let code = EditorWidget::new(&buf);
    assert!(code.should_draw_cursor(&EditorWidgetState::default()));
    assert!(
        !code
            .ignore_keyboard(true)
            .should_draw_cursor(&EditorWidgetState::default())
    );
    // A focus-less *non-code* field is not an active surface, so it must not blink its caret
    // either.
    assert!(
        !EditorWidget::new(&buf)
            .code_mode(false)
            .should_draw_cursor(&EditorWidgetState::default())
    );
}

#[test]
fn mouse_interaction_gated_on_cursor_bounds() {
    // Regression for modal click-outside-to-close: the editor must report `Text` only while the
    // cursor is over its own bounds. Reporting it unconditionally makes iced `Stack` levitate the
    // cursor over a modal's backdrop `mouse_area`, which then bails on the Levitating cursor and
    // never delivers the click.
    let bounds = Rectangle::new(Point::new(10.0, 10.0), Size::new(100.0, 40.0));

    let inside = mouse::Cursor::Available(Point::new(50.0, 30.0));
    assert_eq!(
        editor_mouse_interaction(inside, bounds),
        mouse::Interaction::Text
    );

    let outside = mouse::Cursor::Available(Point::new(300.0, 300.0));
    assert_eq!(
        editor_mouse_interaction(outside, bounds),
        mouse::Interaction::default()
    );

    let levitating = mouse::Cursor::Levitating(Point::new(50.0, 30.0));
    assert_eq!(
        editor_mouse_interaction(levitating, bounds),
        mouse::Interaction::default()
    );

    assert_eq!(
        editor_mouse_interaction(mouse::Cursor::Unavailable, bounds),
        mouse::Interaction::default()
    );
}