Skip to content

fix(renderer): update selection focus on mouseUp for multiplexer compatibility#935

Open
INONONO66 wants to merge 3 commits intoanomalyco:mainfrom
INONONO66:fix/selection-mouseup-multiplexer
Open

fix(renderer): update selection focus on mouseUp for multiplexer compatibility#935
INONONO66 wants to merge 3 commits intoanomalyco:mainfrom
INONONO66:fix/selection-mouseup-multiplexer

Conversation

@INONONO66
Copy link
Copy Markdown

Summary

Terminal multiplexers (e.g. cmux) may not forward mouse drag events to child processes. Without drag events, startSelection sets both anchor and focus to the mouseDown position, but updateSelection is never called during the drag. When mouseUp fires, finishSelection runs with the focus still at the anchor — resulting in a single-character selection.

Fix

Call updateSelection with the mouseUp coordinates before finishSelection, so the selection always spans from mouseDown to mouseUp at minimum.

In normal terminals (where drag events are forwarded), the last drag and mouseUp share the same coordinates, making this a no-op.

Reproduction

  1. Run an OpenTUI app inside a terminal multiplexer that doesn't forward drag events (e.g. cmux)
  2. Drag-select text
  3. Only the first character is selected/copied

Test

Added "selection mouseUp without drag events updates focus to release coordinates" to renderer.mouse.test.ts — simulates the multiplexer scenario by calling pressDown then release with no intermediate moveTo.

…atibility

Terminal multiplexers (e.g. cmux) may not forward mouse drag events to
child processes. Without drag events, startSelection sets anchor and
focus to the same mouseDown position. When mouseUp fires,
finishSelection is called without the focus ever being updated,
resulting in a single-character selection.

Call updateSelection with the mouseUp coordinates before finishSelection
so the selection always spans from mouseDown to mouseUp at minimum.
In normal terminals this is a no-op since the last drag and mouseUp
share the same coordinates.
@simonklee
Copy link
Copy Markdown
Member

/fmt

@simonklee
Copy link
Copy Markdown
Member

/review

import type { MouseEvent } from "../renderer.js"
import type { RenderContext } from "../types.js"
import type { Selection } from "../lib/selection.js"
import { beforeEach, describe, expect, test } from "bun:test";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file has been reformatted with semicolons added throughout. According to AGENTS.md, the project uses oxfmt (semi: false). The main branch has no semicolons in this file. This looks like an unintended formatter change - consider reverting the semicolon additions to keep the file consistent with the rest of the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants