Skip to content

Fix table text copy not matching selection#2175

Merged
dgageot merged 3 commits intodocker:mainfrom
yunus25jmi1:fix/table-copy-selection-mismatch
Mar 19, 2026
Merged

Fix table text copy not matching selection#2175
dgageot merged 3 commits intodocker:mainfrom
yunus25jmi1:fix/table-copy-selection-mismatch

Conversation

@yunus25jmi1
Copy link
Contributor

Description

Fixes issue #2167 where text copied from tables did not match the visual selection.

Root Cause

When selecting text in tables, the copied content did not match the visual selection because border characters (│, ─, etc.) were not properly accounted for when mapping visual column positions to text content.

The previous implementation used a simple offset calculation that subtracted the total border width from column positions, but this didn't account for the actual positions of border characters within the line.

Changes

pkg/tui/components/messages/clipboard.go

  • Added visualToRune mapping to track which runes correspond to which visual columns
  • Implemented findClosestRuneIndex() helper function to map visual column positions to rune indices
  • Updated extractSelectedText() to properly map visual selection positions to text content

How It Works

  1. When extracting selected text, the code now builds a map of visual column positions to rune indices in the stripped text
  2. For each rune in the original line, it tracks whether it's a border character (skipped) or content (kept)
  3. The visual column position is calculated by summing the display width of each rune
  4. When extracting the selection, the code maps the visual start/end columns to the corresponding rune indices in the stripped text

Testing

  • ✅ Code compiles successfully
  • ✅ Existing tests pass
  • ✅ Manual testing required for table selection in TUI

Related Issue

Fixes #2167

@yunus25jmi1 yunus25jmi1 requested a review from a team as a code owner March 19, 2026 14:36
When selecting text in tables, the copied content did not match
the visual selection because border characters (│, ─, etc.) were
not properly accounted for when mapping visual column positions
to text content.

The fix maps visual column positions from the rendered line (with
borders) to the stripped line (without borders) by tracking which
runes correspond to which visual columns, ensuring the copied text
matches what the user selected.

Fixes: docker#2167

Signed-off-by: Md Yunus <admin@yunuscollege.eu.org>
@yunus25jmi1 yunus25jmi1 force-pushed the fix/table-copy-selection-mismatch branch from 0dd1255 to 89fbd72 Compare March 19, 2026 14:39
@dgageot dgageot merged commit db5794c into docker:main Mar 19, 2026
4 checks passed
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.

Copy text in tables does not match selection

2 participants