Skip to content

feat: add pwsh-mouse-selection option#212

Closed
jun2077681 wants to merge 1 commit into
psmux:masterfrom
jun2077681:feat/pwsh-mouse-selection
Closed

feat: add pwsh-mouse-selection option#212
jun2077681 wants to merge 1 commit into
psmux:masterfrom
jun2077681:feat/pwsh-mouse-selection

Conversation

@jun2077681

Copy link
Copy Markdown

Summary

Adds a new pwsh-mouse-selection session option (boolean, default off) that opts into Windows 11 PowerShell-parity drag selection behaviour for the client-side rsel path.

Closes #211.

When the option is on

  • Pane-aware overlay clipping — fixes the latent bug where rsel paints the full terminal width on intermediate rows, bleeding into neighbouring panes.
  • Selection persists on mouse-up — no implicit copy-on-release. Copy is explicit via right-click, Ctrl+Shift+C, or smart Ctrl+C.
  • Double-click / triple-click — select word / whole line within the originating pane.
  • Ctrl+click extends the existing selection to the click point. (Shift+click is reserved by Windows Terminal for its own native selection override and cannot be reclaimed.)
  • Alt+drag produces a rectangular (block) selection.
  • Key bindings: Ctrl+Shift+C (copy), Ctrl+Shift+V (paste from clipboard), and smart Ctrl+C (copy-if-selected, SIGINT otherwise).
  • Overlay colour is white to more closely match Windows Terminal's native selection.

Default remains off, so existing behaviour is unchanged for anyone who does not opt in.

Usage

# ~/.psmux.conf
set -g mouse on
set -g pwsh-mouse-selection on

Changes

  • src/types.rsAppState.pwsh_mouse_selection field + default.
  • src/server/option_catalog.rs, src/server/options.rs, src/config.rs, src/server/mod.rs — option plumbing parallel to scroll-enter-copy-mode, and pwsh_mouse_selection included in both dump JSON serialisation sites.
  • src/client.rsDumpState.pwsh_mouse_selection field, client_pwsh_selection local mirroring the dump, and gated drag/key handlers.
  • Refactor: hoisted PaneLeaf / collect_leaves / char_at_col from inside extract_selection_text to module scope so word_bounds_at can share them; added normalize_selection helper used by extract_selection_text and the render path; added row_chars helper turning the double-click word scan from O(n²) to O(n).

Notes

  • Shift+click is not used because Windows Terminal reserves it as a native-selection override regardless of app-level mouse tracking; Ctrl+click is used instead.
  • Auto-scroll during drag at pane edges is out of scope — rsel operates on visible content only, and scrolling the pane scrollback is copy mode's job.

새 세션 옵션 `pwsh-mouse-selection` 추가 (기본 off).
On일 때 Windows 11 PowerShell 스타일의 드래그 선택 동작을 제공합니다:
  - pane 경계 존중 (rsel overlay clip)
  - mouseup 후 선택 유지, 명시적 복사 시에만 해제
  - 더블클릭 단어 선택, 트리플클릭 줄 선택
  - Ctrl+클릭으로 선택 확장 (Shift+클릭은 Windows Terminal 예약)
  - Alt+드래그 블록(사각형) 선택
  - Ctrl+Shift+C / Ctrl+Shift+V / Ctrl+C 스마트 키바인딩
  - 흰색 오버레이

기본값 off이므로 기존 사용자 동작 변경 없음.

리팩토링:
  - `extract_selection_text` 내부 헬퍼(`PaneLeaf`/`collect_leaves`/`char_at_col`)를
    module scope로 끌어올려 `word_bounds_at`와 공유
  - `normalize_selection` 헬퍼 추출 (extract + render 중복 제거)
  - `row_chars` 헬퍼로 word-scan O(n^2) -> O(n)

Closes psmux#211
@jun2077681

Copy link
Copy Markdown
Author

I found a bug in copy and paste when applying the PR. I am leaving this here because I do not have time to fix it.

psmux added a commit that referenced this pull request Apr 13, 2026
Adds a new pwsh-mouse-selection session option (boolean, default off) that opts
into Windows 11 PowerShell parity selection behavior for the client side rsel
path.

When the option is on:
  - Pane aware overlay clipping (fixes bleed into neighboring panes)
  - Selection persists on mouse up (copy only via right click, Ctrl+Shift+C,
    or smart Ctrl+C)
  - Double click word / triple click line selection within originating pane
  - Ctrl+click extends existing selection (Shift+click reserved by WT)
  - Alt+drag produces rectangular (block) selection
  - Ctrl+Shift+C (copy), Ctrl+Shift+V (paste), smart Ctrl+C bindings
  - White overlay color (closer to Windows Terminal native selection)

Default stays off so existing behavior is unchanged.

Refactored PaneLeaf/collect_leaves/char_at_col from inside
extract_selection_text to module scope for reuse by word_bounds_at.
Added normalize_selection and row_chars helpers.
Added 9 regression tests in tests-rs/test_client.rs covering
normalize_selection, row_chars, char_at_col, is_word_char,
extract_selection_text block mode, word_bounds_at, and default option value.

Based on PR #212 by @jun2077681.
Closes #211.
@psmux

psmux commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Merged manually into master at commit 4b5b5a4 with 9 additional regression tests. All 904 tests pass. Thank you @jun2077681!

1 similar comment
@psmux

psmux commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Merged manually into master at commit 4b5b5a4 with 9 additional regression tests. All 904 tests pass. Thank you @jun2077681!

@psmux psmux closed this Apr 13, 2026
@psmux

psmux commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Hey @jun2077681, I apologize for missing your comment about the copy/paste bug earlier. I should have addressed that before closing.

I went back and re reviewed the code carefully. I found and fixed one inconsistency in the right click copy cleanup path: it was not resetting rsel_pane_rect and rsel_block after copying, while all other copy paths (Ctrl+Shift+C, smart Ctrl+C, legacy copy on release) do. This could leave stale pane clipping state across selections. Fixed in the latest push.

I also ran the full Win32 TUI E2E test suite (8/8 pass) and verified:

  • Ctrl+Shift+C copies selection to clipboard correctly
  • Smart Ctrl+C copies when selection active, sends SIGINT otherwise
  • Selection persists on mouse up (no copy on release) when option is on
  • Legacy copy on release works when option is off

Could you share a bit more about what specific copy/paste behavior you observed? For example:

  • Was it related to Ctrl+Shift+V paste, right click paste, or the copy side?
  • Did you see double pasting, missing text, or something else?
  • Were you testing in Windows Terminal or conhost?

Any details would help me track down and fix the exact issue you ran into. Thanks again for calling it out!

psmux added a commit that referenced this pull request Apr 13, 2026
The right-click copy handler was not clearing rsel_pane_rect and rsel_block
after copying, while all other copy paths (Ctrl+Shift+C, smart Ctrl+C,
legacy copy-on-release) properly reset both. This could leave stale pane
clipping state and block mode flag across subsequent selections.

Follow-up to PR #212 (pwsh-mouse-selection).
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.

Windows 11 PowerShell-style mouse selection parity

2 participants