Mouse event handling system refactoring complete
The mouse event handling refactoring is complete. All builds, lints, and tests pass.
Summary of changes:
- src/view/hit_test.rs - Core types (
Point,MouseEvent,HitTarget,EventResult) and hit-testing functions - src/runtime/mouse.rs - Centralized mouse dispatch with
ClickTrackerandhandle_mouse_press - src/runtime/app.rs - Integrated new system, replacing ad-hoc handlers
The new architecture follows the "hit-test → dispatch" pattern for consistent, maintainable mouse handling across all UI targets.
Now you can run the editor and click on lines below your cursor. The debug output will show the actual values being used:
./target/release/token samples/sample.md
Click on a line below your cursor and observe the stderr output. Share the values and I can pinpoint the issue.
The scroll behavior is working correctly. The debug output confirmed:
visible_linesis being calculated correctly (29 or 57 depending on window size)safe_bottom = top_line + visible_lines - 2withpadding=1- Scrolling only triggers when clicking beyond the safe zone
If you want to increase the padding buffer to ~2 lines, you can change scroll_padding from 1 to 2 in src/model/editor.rs. Would you like me to make that change?
Done. The mouse event handling refactoring is complete:
Commits made:
fe7bed9- Main refactoring: unified hit-test system insrc/view/hit_test.rsand centralized mouse dispatch insrc/runtime/mouse.rs976f821- Cleanup: addressed dead code warnings with targeted#[allow(dead_code)]annotations
Summary:
- New
HitTargetenum with 11 variants for all clickable UI regions hit_test_ui()function with explicit priority orderingClickTrackerfor double/triple-click detection- Exhaustive handling of left and middle mouse clicks
- No compiler warnings, all tests passing
No warnings. The codebase is clean. Here's a summary of findings:
Dead code with #[allow(dead_code)] (intentionally kept for future use):
is_in_tab_bar,is_in_modalin geometry.rs - superseded by hit_test but kept for tests- Various Renderer helper methods - kept for API completeness
- Some HitTarget fields and methods - kept for future context menus
TODOs found (known incomplete features):
src/update/workspace.rs:80- Preview tab behaviorsrc/update/app.rs:70- New file commandsrc/model/editor_area.rs:69,72-is_pinned/is_previewtab flagssrc/model/editor_area.rs:126- min_sizes enforcement
No issues found:
- No partial refactoring left over
- HoverRegion and HitTarget serve different purposes (hover tracking vs click dispatch)
- All mouse handling properly delegated to the new unified system
- Zero compiler warnings
Now let me create a concise, accurate overview:
DEAD CODE TO REMOVE:
| Location | Item | Reason |
|---|---|---|
src/view/geometry.rs:204 |
is_in_tab_bar() |
Only used in tests, superseded by is_in_group_tab_bar |
src/view/geometry.rs:895 |
is_in_modal() |
0 usages, superseded by hit_test_modal |
src/view/geometry.rs:24 |
tab_bar_height() fn |
Wrapper around model.metrics.tab_bar_height, unused |
src/view/geometry.rs:47 |
compute_visible_lines() |
Wrapper, callers use ViewportGeometry::compute_visible_lines directly |
src/view/geometry.rs:57 |
compute_visible_columns() |
Same - wrapper for ViewportGeometry |
src/view/mod.rs:155-180 |
font(), font_size(), ascent(), line_metrics(), dimensions() |
Renderer getters never used |
src/view/mod.rs:2754 |
Renderer::tab_at_position() |
Use geometry::tab_at_position directly |
KEEP (intentionally unused for future/API):
| Location | Item | Reason to Keep |
|---|---|---|
src/view/hit_test.rs |
is_pressed(), is_released(), ctrl() etc |
Will be needed for right-click context menus |
src/view/frame.rs |
CacheStats, measure_width() etc |
Useful debugging/profiling API |
src/runtime/mouse.rs:72 |
ClickTracker::reset() |
May be needed for drag cancellation |
NOT DEAD CODE (bridge is correct architecture):
| Location | Item | Status |
|---|---|---|
src/update/text_edit.rs |
bridge_text_edit_to_editor() |
Active - maps unified TextEditMsg to EditorMsg |
Want me to remove the dead code items?
Done. Here's the summary of cleanup:
Removed (116 lines deleted):
| File | Items Removed |
|---|---|
src/view/geometry.rs |
TAB_BAR_HEIGHT constant, tab_bar_height(), is_in_tab_bar(), is_in_modal(), compute_visible_lines(), compute_visible_columns(), and their tests |
src/view/mod.rs |
Renderer::font(), font_size(), ascent(), line_metrics(), tab_at_position() |
Kept (actually used):
Renderer::dimensions()- used inapp.rsfor hover tracking
3 commits made this session:
fe7bed9- Main mouse refactoring976f821- Cleanup dead code warnings in hit_test.rsd70dab3- Remove dead code from view module
Fixed. The bug was that EventResult only carried redraw/focus information but not the actual Cmd returned by update(). When double-clicking a file in the sidebar, the Cmd::Batch([Cmd::Redraw, Cmd::DebouncedSyntaxParse]) was being discarded.
Summary of fix:
- Added
cmd: Option<Cmd>field toEventResult::Consumed - Added
consumed_with_cmd()helper to create results with commands - Updated sidebar item double-click handler to capture and return the command
- Updated
handle_mouse_pressto use the command fromEventResultif present
Everything is already committed. Let me check the recent commits and update the changelog:
Done. Changelog updated with:
Changed:
- Unified mouse event handling with hit-test system
- Dead code cleanup from view module
Fixed:
- Sidebar double-click now properly triggers syntax highlighting