[MEDIUM] Multiview mouse coordinate translation incorrect for child views #3

Closed xenolandscapes.com
Closed opened by xenolandscapes.com

In src/cursed/multiview.lua, the mouse_forward function in the keymap computes rel_y from Multiview.child_at() and then sets the forwarded mouse event's y to rel_y (the y relative to the child's body start). However, SpanManager:screen_to_file() in src/cursed/span_manager.lua does not subtract the view's _viewport_y from the passed sy before calling View:viewport_line_at_row(). The child's _viewport_y is set to the body y offset during rendering, so the forwarded rel_y is misinterpreted as an absolute screen y, causing incorrect line/col resolution.

Moreover, the conversion of start_y for drag events (me.start_y - (me.y - rel_y)) is also based on the same erroneous rel_y and will be off by the header height and child offset.

Impact: Mouse clicks in multiview children (clicking to focus, drag to select, wheel scrolling) may land on the wrong buffer position or on lines above/below the intended target.

Root cause: SpanManager:screen_to_file() should subtract view._viewport_y from sy before passing to viewport_line_at_row(). Additionally, the mouse event forwarded should retain the original absolute screen x/y and let the child's own span_manager handle the offset via the already-set _viewport_y during its render cycle.

Recommended fix:

  1. In SpanManager:screen_to_file(), adjust sy by subtracting view._viewport_y before calling view:viewport_line_at_row().
  2. In Multiview's mouse forwarding, pass the original me.x and me.y unchanged, and only convert start_x/start_y by adding me - (child_abs_y - me.y) (or similar).

Commit range: 335f21a5

Related commits: 335f21a5

Sign up or Sign in to add to the discussion.