Skip to content

fix: text selection issue(#6)#7

Merged
Poorgramer-Zack merged 1 commit intomainfrom
fix/text-selection-issue
Jan 12, 2026
Merged

fix: text selection issue(#6)#7
Poorgramer-Zack merged 1 commit intomainfrom
fix/text-selection-issue

Conversation

@Poorgramer-Zack
Copy link
Owner

@Poorgramer-Zack Poorgramer-Zack commented Jan 12, 2026

[PR] Fix Selection Highlight Visibility in Non-TUI Terminals (Fixes #6)

Summary

Fixed the issue where text selection highlight was invisible in regular shell operations, making users think text selection was not supported.

Problem

  • In a previous commit (c1a6e99), to fix line gaps, paintCellBackground logic was modified
  • This change caused: when text was selected, cell backgrounds would cover up the selection highlight
  • Result: In non-TUI applications (like PowerShell/bash), selecting text showed no highlight, making users believe selection was broken

Root Cause

Rendering order problem in the paint pipeline:

  1. render.dart paints the full terminal background first (line 462-465)
  2. Then paints the selection highlight (line 483-490)
  3. Finally paints each cell individually (line 495-502)
  4. When cell backgrounds were painted, they covered the previously drawn selection highlight

Before this fix:

} else if (colorType == CellColor.normal) {
  color = _theme.background;  // Paints background -> covers selection
}

After this fix:

} else if (colorType == CellColor.normal) {
  return;  // Skip -> selection remains visible
}

Solution

Restored the early return logic for normal cells in paintCellBackground. Since render.dart already paints the complete terminal background before painting cells and highlights, individual cell background painting is redundant and causes the coverage issue.

Changes Made

Modified File:

  • packages/xterm/lib/src/ui/painter.dart
    • paintCellBackground(): Restored early return for CellColor.normal cells with an updated comment explaining why

Verification

  • ✅ Text selection highlight now displays correctly in non-TUI terminals (PowerShell, bash, cmd, etc.)
  • ✅ Ran flutter analyze on the xterm package - No errors found
  • ✅ Tested with hot reload - works correctly

Known Limitations

Selection Behavior: Since xterm renders Terminal UI by simulating the terminal buffer in Flutter, text selection will select by "line" rather than by exact character boundaries. However, the text copy-paste functionality works correctly and will copy the actual selected text content.

Copilot AI review requested due to automatic review settings January 12, 2026 08:12
@Poorgramer-Zack Poorgramer-Zack self-assigned this Jan 12, 2026
@Poorgramer-Zack Poorgramer-Zack merged commit 67d0d45 into main Jan 12, 2026
9 checks passed
@Poorgramer-Zack Poorgramer-Zack deleted the fix/text-selection-issue branch January 12, 2026 08:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where text selection highlighting was invisible in non-TUI terminal operations (PowerShell, bash, cmd, etc.), making it appear that text selection was not supported. The problem was introduced in a previous commit (c1a6e99) that attempted to fix line gaps by always painting cell backgrounds, which inadvertently covered selection highlights.

Changes:

  • Restored early return logic in paintCellBackground() for normal cells to prevent covering selection highlights
  • Removed incorrect comment that claimed painting normal cell backgrounds prevented line gaps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -242,9 +242,7 @@ class TerminalPainter {
if (cellData.flags & CellFlags.inverse != 0) {
color = resolveForegroundColor(cellData.foreground);
} else if (colorType == CellColor.normal) {
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Consider adding a comment to explain why normal cells return early. This would help future maintainers understand that the terminal background is already painted in render.dart (lines 462-465), and painting normal cell backgrounds here would cover selection highlights and other overlays. For example: "Skip painting background for normal cells - the terminal background is already painted in render.dart and painting here would cover selection highlights."

Suggested change
} else if (colorType == CellColor.normal) {
} else if (colorType == CellColor.normal) {
// Skip painting background for normal cells - the terminal background is
// already painted in render.dart and painting here would cover selection
// highlights and other overlays.

Copilot uses AI. Check for mistakes.
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.

Terminal text selection is disabled; Ctrl+C conflicts with copy behavior

2 participants