Repository navigation
Place the scrollback draft cursor on mouse clicks - #2211
Conversation
eric8810
left a comment
There was a problem hiding this comment.
Reviewed the scrollback-only delta. The screen derives the composer cell from the rendered viewport and dock, the existing textarea does the wrapped/wide-character mapping, and terminal mouse reporting is gated on a nonempty draft with no prompt or picker. The guide documents the temporary tradeoff for native wheel scrolling and selection while editing.
The checks for this head passed. The author's tmux run verifies the mouse mode before and after submission plus the exact edited multiline input; I did not rerun it independently. This approval is for the delta on #2210. Its fullscreen review is separate; recheck CI on the rebased stack after that base lands.
zerob13
left a comment
There was a problem hiding this comment.
Reviewed the scrollback-only delta at ae694e9f38348204a488452062d17ed7b83c7f8a on #2210's head. Two behavior issues block this change:
- Map a click to the rendered draft, not a newer draft state. The scrollback handler and render loop can use old screen coordinates with the new textarea scroll offset. When a new row takes the draft past its visible height before repaint, a click on the visible first row can edit the second row. With rendering delayed, verify that a click edits the displayed cell or leaves the cursor unchanged until the corresponding frame is drawn.
- Restore the terminal mouse mode if exit interrupts mouse-off. The toggle clears the flag before queuing the reset, and Unix cleanup uses that flag to decide whether to reset. A signal in that gap can leave terminal reporting active after the application exits. Verify that native selection and scrolling are restored on exit even if the mouse-off write has not reached the terminal.
These are static findings; exact stack CI passed. The separate fullscreen mapping finding belongs to #2210. Recheck the stack and its CI after the base changes.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Requesting changes. Two behavior findings remain, and the base branch moved after this head, so the PR also conflicts and needs a rebase.
The PR places the scrollback draft cursor on a left click while a nonempty draft is being edited. Mouse reporting is enabled only then; Screen::composer_hit maps the screen cell to the dock-relative cell, and Composer::click reuses the textarea's rendered width, scroll and element boundaries. Clearing or submitting the draft, opening a picker or prompt, or turning the setting off releases the mouse. The CLI guide, the /settings label, the translations and the tmux inventory match the behavior.
I agree with zerob13 on both blocking behavior findings: a local probe reproduced the first (a click on the displayed first row landed on the second line after an append moved the textarea scroll), and the second follows the modes::clear before writer.send order in terminal/mod.rs:324-335.
Blocking, base: the base branch moved to d99838e (fix: map fullscreen composer clicks with the rendered height) after this head was pushed. git ls-remote origin refs/heads/dimagent/2179-composer-click returns d99838e, and git merge-tree --write-tree d99838e1 HEAD conflicts in docs/architecture/tui-e2e.md and scripts/tui-tmux/scenarios.mjs; GitHub reports the PR as unmergeable. Both changes insert a composer scenario and its inventory row at the same point, so keep both fullscreen_composer_click_with_a_clipped_task_strip and scrollback_click_places_draft_cursor, then run node --test scripts/tui-tmux.test.mjs and the two composer tmux scenarios. The Rust side auto-merges into the intended shape: frame.composer is recorded before the fullscreen padding and the condition no longer checks self.fullscreen.
P2 status: d99838e now records frame.composer before padding (tui.rs:6588-6602), which fixes #2210 review 6068062967. Scrollback never padded, so after the rebase frame.composer.height is rows.len(), the height render_rows actually rendered (composer/mod.rs:1258-1262), and both modes map with the textarea viewport. No #2210 P2 remains; the stale-frame click race is separate.
P3: App::mouse still documents the setting as fullscreen-only (tui.rs:1321-1322), while this PR makes it govern scrollback and renames the settings row to "Mouse" (settings_panel.rs:218, README.md:1241). Failure: a reader of the struct contract can misjudge the new condition's scope and simplify it back to fullscreen only. Fix: say both TUI modes read tuiMouseMode.
P3, inline: Screen::composer_hit has no contract comment and no focused test for its mixed coordinate space, the padding layout inserts above the dock, or a clipped viewport (screen.rs:131-138, screen.rs:161-184). The committed scenario covers only the 60-column wrapped wide-character case (scenarios.mjs:536-563). Details and a suggested test are in the comment on screen.rs:131.
Optional note: while the mouse is captured, a terminal scrollback scroll made with the scrollbar or a terminal key binding is invisible to the client. A click on a history row after that scroll is mapped against the live viewport and can move the hidden draft cursor. The README already ties native selection and wheel scrolling to the terminal override gesture (README.md:1160); naming the scrollbar case there as a known limitation is enough.
Cross-PR: origin/main c68dad5a (the #2178 merge) merges cleanly and has not touched these files since the merge base. #2197 eccd6d38 is a sibling on the same base; it changes tui.rs, settings_panel.rs and the i18n files but not the mouse lines, and the merge is clean. #2174 4f59f2fa and #2206 3c4ef46e do not overlap. #2178 has merged as c68dad5a and does not touch these files. #1881 ff9825d2 merges cleanly apart from docs/design/plugins/Report.md, a conflict that also exists between #1881 and main, so it is not caused here.
Verification: cargo test --locked -p dim-cli --lib passed 823 tests on ae694e9 with isolated HOME, TMPDIR and XDG under the review data dir. node --test scripts/tui-tmux.test.mjs passed 6 tests, including the scenario inventory check. Temporary probes confirmed the stale-frame click race and the Screen::composer_hit padding and cut-viewport mapping; both were reverted. tmux is not installed here, so I did not run the new scenario or the fullscreen one; CI does not run the suite. CI on ae694e9 passes all required checks. The additional manual checks in the PR body are not committed and remain unverified.
| self.size | ||
| } | ||
|
|
||
| pub fn composer_hit(&self, x: u16, y: u16) -> Option<(Rect, Position)> { |
There was a problem hiding this comment.
P3. This new mapping has no contract comment and no focused test.
Problem: x is a screen column while the returned row is relative to the dock, and the result depends on self.top, self.viewport_height and the blank rows layout inserts above the dock (screen.rs:161-184). The committed scenario covers one 60-column wrapped row with a wide character (scripts/tui-tmux/scenarios.mjs:536-563); it does not cover a padded dock or a viewport that cuts the live region, and the tmux suite is local-only.
Failure: a later change to the padding or clipping arithmetic shifts clicks by the padding rows while every CI check stays green; clicks then place the draft cursor on the wrong wrapped line.
Fix: add a /// contract note (screen columns, dock-relative rows, None outside the rendered box) and a unit test here for a cut tail and a shrinking-tail padded frame. I wrote such a probe locally and it passes.
There was a problem hiding this comment.
Fixed: composer_hit has the contract comment at crates/dim-cli/src/ui/render/screen.rs:131-133 and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-924. The test covers a 14-row live region clipped by a 12-row screen, the padding layout inserts for a shrinking tail, the mixed screen-column and dock-row space, and cells outside the box on the left and top edges, so it would catch a screen-row mapping or a box that ignores its area. One optional gap remains: the assertions still pass if the dock offset or self.top is dropped, so the arithmetic is not fully pinned; the details and the fix are in an inline comment on screen.rs:919. The two P2 findings from the round 1 review are fixed as described in the review body.
zerob13
left a comment
There was a problem hiding this comment.
Reviewed 57f9390aee06c119e009e3c781a9297994663df6 against 626f280797c1f8a88df350429d97bd22bc88fb01. The SIGTERM reset is fixed: the isolated Linux PTY check confirmed that the handler writes all three mouse-disable sequences before exit even with a pending queued write. The retargeted branch is mergeable and exact CI passed.
Remaining acceptance: a delayed scrollback click must not edit a different row. The new guard drops already-decoded reports and rejects clicks during repaint. A report that arrives after repaint can still be applied to the new textarea scroll offset. In the isolated tmux check, the click was on the cell showing draft-row-11 before a paste scrolled the draft. With the report delivered afterward, typing X produced Xdraft-row-12. Verify that the originally displayed text is targeted or the caret remains unchanged, including for a report delivered across terminal reads. Click and repaint guards · Input queue
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Approving at 57f9390. Both P2 findings from round 1 are closed, the P3 items are addressed, the base conflict is gone, and the required checks pass at this head.
P2, stale scrollback click: fixed. A scrollback paint now drops mouse reports already decoded against the previous frame (crates/dim-cli/src/ui/tui.rs:473, crates/dim-cli/src/ui/tui.rs:497-500), and the click arm requires mouse && !dirty && !terminal.writing() && Press && screen.size() == terminal.size() (crates/dim-cli/src/ui/tui.rs:583-591). There were two deterministic paths to the round 1 mismatch: a click decoded behind an earlier event stayed in the queue across an append and its repaint, and a repaint due when the append was applied could be deferred because the writer was busy, leaving Screen::composer from the old frame while Composer::click used the new textarea scroll. The discard closes the first; !dirty and !terminal.writing() close the second. The only residual is a report still in the OS input buffer, generated before a repaint and read after it: it is interpreted against the new frame like any click at read time. That is inherent to terminal input and not a defect I would block on.
P2, mouse cleanup after a fatal signal: fixed. set_mouse(false) no longer clears Mode::Mouse; mouse_requested carries the requested state (crates/dim-cli/src/ui/terminal/mod.rs:319-332), set_fullscreen(false) keeps the bit and clears only AltScreen (crates/dim-cli/src/ui/terminal/mod.rs:289-295), and release_modes clears the live set only after the restore (crates/dim-cli/src/ui/terminal/mod.rs:600-603). A signal between the disable and the queued reset now still writes the mouse reset from the live set, and no code reads modes::is_live(Mode::Mouse) as current state; the old mouse() getter is gone. Repeated resets on exit, external editor release and retake, and fullscreen toggles are idempotent, and the Windows restore uses the same mode set.
P3, optional: the new mapping test does not pin the dock offset or the screen top. Problem: the only positive click at crates/dim-cli/src/ui/render/screen.rs:919 is on second, whose dock row is 2 under both the correct dock_rows - from_bottom and a wrong from_bottom, and set_origin(0) keeps self.top at 0 in both frames. Failure: replacing dock_row with from_bottom, or row with y, keeps the test green; in a real frame a click on the bottom rows of the viewport (the composer border or status) would then be accepted as the first text row, or every click would shift by the shell origin. Evidence: I applied both mutations and the committed test passed each time; both are reverted. Fix: also click the first row (correct cell 1; with the from-bottom-only formula, 3, outside the two-row area) and render one frame with a non-zero origin. Not blocking.
P3, round 1 thread: the contract comment (crates/dim-cli/src/ui/render/screen.rs:131-133) and the focused test (crates/dim-cli/src/ui/render/screen.rs:906-924) are present and cover a 14-row live region clipped by a 12-row screen, the padding layout inserts for a shrinking tail, the mixed screen-column and dock-row space, and cells outside the box on the left and top edges. The sensitivity gap above is the only remainder.
Round 1 items: the base conflict is resolved by merging main at 7abf827; both composer scenarios survive (scrollback_click_places_draft_cursor and fullscreen_composer_click_with_a_clipped_task_strip); App::mouse now documents both modes (crates/dim-cli/src/ui/tui.rs:1327).
CI and merge: the PR check run 45764105439 at 57f9390 succeeded (verify linux, macos-native, windows-cli, scripts, ci-ok). git merge-tree --write-tree origin/main 57f9390a with origin/main 626f280 is trivially clean because main is an ancestor; GitHub reports MERGEABLE, and the BLOCKED state comes from review requests, not a conflict. #2210 is merged at 626f280; its frame.composer-before-padding mapping and the fullscreen files are unchanged from that merge, and this PR only removes the self.fullscreen gate (crates/dim-cli/src/ui/tui.rs:6609), so the rendered-height mapping is preserved. Cross-PR: #2197 49c14ad still touches tui.rs, settings_panel.rs and the i18n files, not the mouse lines, and merges cleanly; #2214 2bbbb18, #2174 3914eaa, #2212 cfb6c05, #2206 f125d5f and #2223 4ce2dd7 do not touch these files and merge cleanly.
Verification: filtered cargo test --locked -p dim-cli --lib runs for ui::render::screen (31), ui::terminal (33), composer (88), mouse (4) and scrollback (7) pass with isolated HOME, TMPDIR, XDG and target directories. node --check scripts/tui-tmux/scenarios.mjs and node --test scripts/tui-tmux.test.mjs (6 tests) pass. tmux is not installed here, so I did not run the new scenario, the fullscreen composer scenario, or a fatal-signal exercise; CI does not run the tmux suite, so the new stale-click and exit-reset assertions and the signal path remain verified by code reading and the author's local run.
| drive(&mut screen, &mut emu, &f); | ||
| let drawn = emu.rows_text(); | ||
| let y = drawn.iter().position(|row| row == "second").unwrap() as u16; | ||
| assert_eq!(screen.composer_hit(5, y), Some((area, Position::new(5, 2)))); |
There was a problem hiding this comment.
[P3] This test passes for two wrong mappings, so it does not fully pin the arithmetic it was added for. I changed dock_row to usize::from(from_bottom) (dropping the dock_rows offset) and the test still passed because the only positive click is on second, whose dock row equals its from-bottom distance in both frames. I also changed row to y (dropping self.top) and it still passed because set_origin(0) keeps self.top at 0. Failure: with either change, a click on the composer border or status row at the bottom of the viewport is accepted as the first text row, or every click shifts by the shell origin, while CI stays green. Fix: also assert a click on the first row (correct cell 1; from-bottom-only 3, outside the two-row area) and render one frame with a non-zero origin. Both mutations are reverted.
There was a problem hiding this comment.
Remains at ee8dcae: the new commit does not touch crates/dim-cli/src/ui/render/screen.rs. I re-applied both mutations at this head and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-923 still passes each time. let dock_row = usize::from(from_bottom); drops the dock offset, and the positive click on second cannot distinguish it. let row = y; drops self.top, and set_origin(0) keeps both frames at 0. The new tmux scenario exercises the mapping end to end, but CI does not run that suite, so the unit gap stands. The fix from the original comment still applies: also click the first row (cell 1 under the correct mapping; 3 under the from-bottom-only formula, outside the two-row box) and render one frame with a non-zero origin. Both mutations are reverted. Optional at this round.
zerob13
left a comment
There was a problem hiding this comment.
Reviewed ee8dcae40933f77491e908fd9dc87322366857ca. The isolated tmux case that previously edited the wrong row now leaves the caret in place when the stale click arrives. The next click uses the newly displayed row and submission preserves the exact edited text. All three focused tmux scenarios passed. The SIGTERM reset remains fixed. This closes my previous change request.
CI remains an independent gate. The earlier Linux attempt failed during App Server storage startup, before the affected tests' assertions; the underlying cause is unverified. The latest Linux attempt was already running at recheck.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Approving at ee8dcae. The new commit closes the remaining acceptance in the other review: a delayed scrollback click after the draft scrolls leaves the caret unchanged, and the next click places it. The round-2 P3 on the screen mapping test is unchanged and remains optional. One required check, verify (linux), failed at this head in tests that this diff does not touch; the details are at the end.
New click guard. Composer::rendered_scroll reports the textarea scroll (crates/dim-cli/src/ui/composer/mod.rs:1239-1242). click_scroll starts unset (crates/dim-cli/src/ui/tui.rs:320), is cleared when mouse reporting is off or fullscreen is active, and otherwise takes the current scroll only while no frame is pending (crates/dim-cli/src/ui/tui.rs:520-524). The scrollback arm accepts a press only when click_scroll.replace(current) == Some(current) (crates/dim-cli/src/ui/tui.rs:588-601), so the first composer press after a scroll change is swallowed, records the new scroll, and the next press places the cursor. The initialization runs in the same iteration before next_event (crates/dim-cli/src/ui/tui.rs:546-549), so a press that reaches the arm in a clean iteration cannot compare against None: it is accepted unless a dirty frame, a pending write or a size mismatch dropped it earlier under the pre-existing gates. Those gates do not record the scroll, so such a press is lost and the next press becomes the acknowledgment. A resize drops presses until the screen and terminal sizes match again; the reflow then follows the same scroll comparison, so a rewrapped draft that changes the textarea scroll costs one click. A press outside the composer, a release or a non-press does not consume the acknowledgment, and a clean frame with an unchanged scroll does not change the value, so those cases do not swallow a later composer click. The guard therefore rejects exactly one composer press per scroll change, including a press made after the user has seen the new view; that is the documented tradeoff and matches the scenario. It is keyed to the textarea scroll only: a frame that shifts or grows the composer without changing the scroll, such as a draft below the seven-row limit that gains a row, is not detected. That is the report still in the OS input buffer that the round-2 review accepted as inherent to terminal input, not a new regression.
Tmux scenario. The scenario does pin the new check, though not with the step that first looks like it. The new-row batch (scripts/tui-tmux/scenarios.mjs:590) sends the paste, the click and X together; the render discards the queued press, and new-rowX would also pass under the round-2 guards alone. The last-row step (scripts/tui-tmux/scenarios.mjs:593-599) sends the paste in one call, waits for the new frame, then sends the press and Y; that press cannot be in the queue at a render, so only click_scroll can reject it. With the check removed, the click lands on the visible row now showing a draft row, the captured text is Ydraft-row-k, and the last-rowY assertion fails. The final press (scripts/tui-tmux/scenarios.mjs:600-604) must then place the cursor: the waitFor on Z${target} and the exact submitted text with draft[k] = "Z" + token pin the row and the column, so an acknowledgment that never re-arms also fails. Timing is sound: the waits put the clicks on a clean, idle frame; the literal newline between the separate bracketed pastes decodes as Ctrl+J rather than Enter; and the 18 single-line pastes stay below the multiline-paste attachment threshold. The residual risk is an unrelated repaint or writer still pending at the Y or Z press, which would drop that press and fail the later Z wait; the captures before each press make that unlikely. tmux is not installed here, so I did not run it; CI does not run the tmux suite, and the node checks pass.
README and tui-e2e. crates/dim-cli/README.md:1160-1163 matches the code: the first press on a text cell after a scroll change acknowledges the new view without moving the cursor, the next places it; clearing or submitting, opening a picker or prompt, or turning mouse off disables reporting; and the warning about the terminal history offset is accurate because the mapping uses Dim's own live frame. The /settings row and crates/dim-cli/README.md:1243 now say mouse input rather than fullscreen mouse. docs/architecture/tui-e2e.md:108 matches the ownership, wide-character and delayed-click checks in the scenario.
Round-2 P3. Remains. The new commit does not touch crates/dim-cli/src/ui/render/screen.rs. I re-applied both mutations at this head: let dock_row = usize::from(from_bottom); (drops the dock offset) and let row = y; (drops self.top). The focused test at crates/dim-cli/src/ui/render/screen.rs:906-923 passes under each, and both are reverted. The suggested fix still applies: click the first row as well (cell 1 under the correct mapping; 3 under the from-bottom-only formula, outside the two-row box) and render one frame with a non-zero origin. Optional at this round; I replied in the thread. The round-1 contract and test thread is unchanged and still fixed.
CI. verify (linux) failed on its first attempt at 06:55:59 and a rerun started at 07:00:09, still in progress. The first attempt: two transport_flow product_protocol tests and one agents::sessions test panicked on initialization timed out (missing settings, modality and storage services) at crates/dim-app-server/tests/transport_flow.rs:405 and crates/dim-app-server/src/agents/sessions/tests.rs:169. The changed files cannot reach those tests: no app-server, runtime or capabilities file is in this diff, dim-app-server has no dim-cli dependency, and the same app-server code passed on #2223's verify (linux) at 06:57:14. The failure reads as environment timeouts rather than a regression from this PR; the rerun should confirm it. The changes, scripts, macos-native and windows-cli checks pass; static-checks, web, acp-registry and dependencies are skipped by the path selection.
Merge and verification. git merge-tree --write-tree origin/main HEAD is clean against origin/main 3b0f013 and against the current remote main 3edabc0 (#2224 merged, 82085a3). #2197 49c14ad and #2223 14d96cf still overlap the changed files (i18n, settings and tui for #2197; tui-e2e for #2223) but merge cleanly and touch different hunks; #2206 c8d5276, #2214 74d5df0 and #2174 01f9a70 (heads moved since the round-2 list) also merge cleanly. GitHub reports MERGEABLE; BLOCKED is the outstanding review request. The worktree is clean at ee8dcae. Targeted tests with isolated HOME, TMPDIR, XDG and target passed: ui::render::screen 31, composer 70, ui::terminal 33, and mouse plus scrollback 11. node --check scripts/tui-tmux/scenarios.mjs and node --test scripts/tui-tmux.test.mjs (6 tests) pass, and both mutation runs above pass the focused screen test.
Fixes #2179. Targets main after the fullscreen fix in #2210. This diff does not modify its fullscreen gesture or include nightly installer changes.
With mouse input enabled, scrollback captures the mouse only while editing a nonempty draft. Clicking an editable cell places the next keystroke there, including after line wrapping and wide characters. Submitting or clearing the draft, opening a picker, or disabling mouse input hands selection and scrolling back to the terminal. While captured, native selection depends on the terminal override gesture.
Design rule checklist and documentation
Cursor movement is a terminal-local edit, not a Session input or a Timeline event. No service face, plugin, loader, infrastructure or ADR changes. The CLI guide and tmux inventory document the behavior.
Verification
Built the CLI from this branch on macOS arm64. All three focused tmux scenarios passed: wrapped and wide-character editing in scrollback, stale clicks during a draft scroll, mouse reset on exit, fullscreen click placement, and fullscreen clipping under a task strip. The tmux scenario inventory and changed Rust formatting passed.