Skip to content

fix: trim trailing whitespace from terminal clipboard copies#3167

Open
Drew-Goddyn wants to merge 1 commit intowavetermdev:mainfrom
Drew-Goddyn:fix/trim-trailing-whitespace-on-copy
Open

fix: trim trailing whitespace from terminal clipboard copies#3167
Drew-Goddyn wants to merge 1 commit intowavetermdev:mainfrom
Drew-Goddyn:fix/trim-trailing-whitespace-on-copy

Conversation

@Drew-Goddyn
Copy link
Copy Markdown

Fixes #2778.

Problem

xterm.js's getSelection() returns lines padded to the full terminal column width. Every copy path passed this directly to navigator.clipboard.writeText(), so pasting into Slack, editors, etc. included hundreds of trailing spaces.

Solution

Adds a term:trimtrailingwhitespace setting (default true) that strips trailing whitespace from each line before writing to the clipboard. Applied to all three copy paths:

  • copy-on-select (termwrap.ts)
  • Ctrl+Shift+C (term-model.ts)
  • right-click Copy context menu (term-model.ts)

OSC 52 is intentionally excluded — that path copies program-provided text, not grid content.

The trim itself uses the same per-line trimEnd() approach already present in bufferLinesToText via translateToString(true).

Setting to false restores the previous behaviour.

Files changed

  • pkg/wconfig/settingsconfig.go — new TermTrimTrailingWhitespace *bool field
  • pkg/wconfig/defaultconfig/settings.json — default true
  • frontend/app/view/term/termutil.tstrimTerminalSelection helper
  • frontend/app/view/term/termwrap.ts — copy-on-select path
  • frontend/app/view/term/term-model.ts — Ctrl+Shift+C and right-click paths
  • Generated: pkg/wconfig/metaconsts.go, frontend/types/gotypes.d.ts, schema/settings.json

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 59a98bf6-57ba-4ed6-9ffd-0fcaea32aa21

📥 Commits

Reviewing files that changed from the base of the PR and between ac0299e and b3cc6ae.

📒 Files selected for processing (8)
  • frontend/app/view/term/term-model.ts
  • frontend/app/view/term/termutil.ts
  • frontend/app/view/term/termwrap.ts
  • frontend/types/gotypes.d.ts
  • pkg/wconfig/defaultconfig/settings.json
  • pkg/wconfig/metaconsts.go
  • pkg/wconfig/settingsconfig.go
  • schema/settings.json

Walkthrough

This PR introduces a new optional feature for trimming trailing whitespace from terminal text selections across the application. A new setting term:trimtrailingwhitespace is added to the configuration schema and default settings (enabled by default). A utility function trimTerminalSelection is implemented to process selection text line-by-line, removing trailing whitespace from each line. The feature is integrated into three copy operations: keyboard shortcut (Ctrl+Shift+C), context-menu "Copy" action, and copy-on-select behavior, with conditional application based on the setting value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: trimming trailing whitespace from terminal clipboard copies, which is the core objective of this PR.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the problem, solution, and all three copy paths affected by the changes.
Linked Issues check ✅ Passed The PR fully addresses issue #2778 by implementing a configurable setting to trim trailing whitespace on terminal copies across all copy paths except OSC 52, matching the expected behavior described in the issue.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the trim trailing whitespace feature: settings configuration, the trimming utility, and updates to the three copy paths; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 1, 2026

CLA assistant check
All committers have signed the CLA.

Fixes wavetermdev#2778. xterm.js getSelection() returns lines padded to the full
terminal column width, resulting in hundreds of trailing spaces when
pasting into external apps.

Adds a term:trimtrailingwhitespace setting (default true) that strips
trailing whitespace from each line before writing to the clipboard.
Applies to all three copy paths: copy-on-select, Ctrl+Shift+C, and
right-click Copy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Drew-Goddyn Drew-Goddyn force-pushed the fix/trim-trailing-whitespace-on-copy branch from 4817f82 to b3cc6ae Compare April 1, 2026 21:25
@Drew-Goddyn Drew-Goddyn marked this pull request as ready for review April 1, 2026 22:13
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 1, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • frontend/app/view/term/term-model.ts - Copy paths updated correctly
  • frontend/app/view/term/termutil.ts - Trim helper implemented correctly
  • frontend/app/view/term/termwrap.ts - Copy-on-select path updated correctly
  • frontend/types/gotypes.d.ts - Generated types updated
  • pkg/wconfig/defaultconfig/settings.json - Default set to true
  • pkg/wconfig/metaconsts.go - Constant added
  • pkg/wconfig/settingsconfig.go - Setting field added
  • schema/settings.json - Schema updated

The implementation correctly handles the optional boolean setting using the !== false pattern, which properly treats undefined as true (the default). The trim helper correctly splits by newlines, trims each line, and joins back together.


Reviewed by minimax-m2.5-20260211 · 348,289 tokens

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.

Copying text includes trailing whitespace to edge of terminal

2 participants