Commit 7d4c6ce
feat: granular text selection + workflow on-response example (#55)
Two items from the deferred audit list.
## Granular text selection
Selection model was line-only: clicking a chat line selected the
whole line, dragging extended row-by-row. Users couldn't select a
substring within a single line (a paragraph fragment, half a
filename, the right half of a diff hunk).
Selection anchors are now `(buffer_line_index, char_offset_in_line)`
pairs instead of `Option<usize>`. New `Renderer::buffer_pos_at(row,
col) -> Option<(usize, usize)>` maps mouse coordinates to a buffer
position, accounting for `content_indent()` and clamping at
end-of-line so dragging past the right edge anchors there.
The viewport paint splits each row into up to three painted runs
(pre-selection, selected with `Attribute::Reverse`, post-selection)
so highlighting happens per-character within a line. Bold-glow
for bright colors is preserved across all three runs.
`selected_text` extracts:
- single-row: char slice [start_col, end_col)
- multi-row: tail of start row + full middle rows + head of end row
Reverse drag (end before start in row-major order) is normalized
so the extracted text is always the visible selection.
Mouse handlers (`MouseDown`, `MouseDrag`, `MouseUp`) now pass
`col` through to `buffer_pos_at` instead of dropping it.
UTF-8 safe: char counts use `chars().count()` everywhere, so
`é` and `🦀` each count as 1 char, not their byte widths.
## workflow.janet on-response example
New `plugins/response_inspector.janet` demonstrates the
`on-response` hook's two distinct capabilities:
1. **Pattern detection + notifications** — calls `harness/notify`
when the agent's reply contains a code block.
2. **Steering string return value** — returns a system-prompt
suffix to be applied on the next turn, asking the agent to
add inline comments when its previous code block lacked them.
Documents the difference between `on-response` (assistant text)
and `on-tool-end` (tool output, where `harness/replace-result`
belongs).
## Test plan
- [x] 6 new tests in `ui::renderer::tests`:
- single-row substring selection
- reverse-drag normalization
- multi-row spans (tail + middle + head)
- empty selection returns None
- UTF-8 char-index correctness (`café 🦀`)
- `buffer_pos_at` clamps past-EOL
- [x] `cargo test --features plugin` -> 612 pass, 0 fail.
- [x] Both build profiles -> 0 warnings.
- [ ] Eyeball: drag in chat to select a substring; verify
reverse-video highlight only covers the selected chars,
clipboard receives the right substring.
Co-authored-by: Yogthos <yogthos@gmail.com>1 parent bf5e98d commit 7d4c6ce
4 files changed
Lines changed: 284 additions & 67 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
622 | 622 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
634 | 635 | | |
635 | 636 | | |
636 | | - | |
| 637 | + | |
637 | 638 | | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
647 | 649 | | |
648 | 650 | | |
649 | 651 | | |
| |||
668 | 670 | | |
669 | 671 | | |
670 | 672 | | |
671 | | - | |
| 673 | + | |
672 | 674 | | |
673 | | - | |
674 | | - | |
| 675 | + | |
| 676 | + | |
675 | 677 | | |
676 | 678 | | |
677 | 679 | | |
| |||
0 commit comments