detached 487b097

fix(tui): VS Code ghost highlight on selection navigation

Forces full attribute reset before clearing each row when selection highlights are present. VS Code's xterm.js doesn't reliably clear background colors on row overwrite without an explicit reset.
commit
487b097da40376bb8504fd476e3cbb1bf1987363
author
patriceckhart · · 2026-04-25 18:49 UTC
parent
6237dd2
signature
unsigned
refs
tag: v0.1.16
2 files · +23 -5
M internal/tui/render.go +22 -1
@@ -198,10 +198,31 @@ func (r *Renderer) Draw(lines []string, cursorRow, cursorCol int) {
198198 }
199199 }
200200
201+ // Detect selection highlights: if the current OR previous frame
202+ // has selection-background rows, force full repaint. VS Code's
203+ // terminal doesn't reliably clear background colors on row
204+ // overwrites, leaving ghost highlights behind.
205+ hasSelection := false
206+ for _, l := range frame {
207+ if strings.Contains(l, "\x1b[48;5;") {
208+ hasSelection = true
209+ break
210+ }
211+ }
212+ if !hasSelection && r.prev != nil {
213+ for _, l := range r.prev {
214+ if strings.Contains(l, "\x1b[48;5;") {
215+ hasSelection = true
216+ break
217+ }
218+ }
219+ }
220+
201221 full := r.prev == nil || len(r.prev) != r.rows
202222 for i := 0; i < r.rows; i++ {
203- if full || forceAll || r.prev[i] != frame[i] {
223+ if full || forceAll || hasSelection || r.prev[i] != frame[i] {
204224 w.WriteString(MoveTo(i+1, 1))
225+ w.WriteString("\x1b[0m") // reset all attributes first
205226 w.WriteString(SeqClearLine)
206227 w.WriteString(frame[i])
207228 }
@@ -198,10 +198,31 @@ func (r *Renderer) Draw(lines []string, cursorRow, cursorCol int) {
198 }198 }
199 }199 }
200 200
201+ // Detect selection highlights: if the current OR previous frame
202+ // has selection-background rows, force full repaint. VS Code's
203+ // terminal doesn't reliably clear background colors on row
204+ // overwrites, leaving ghost highlights behind.
205+ hasSelection := false
206+ for _, l := range frame {
207+ if strings.Contains(l, "\x1b[48;5;") {
208+ hasSelection = true
209+ break
210+ }
211+ }
212+ if !hasSelection && r.prev != nil {
213+ for _, l := range r.prev {
214+ if strings.Contains(l, "\x1b[48;5;") {
215+ hasSelection = true
216+ break
217+ }
218+ }
219+ }
220+
201 full := r.prev == nil || len(r.prev) != r.rows221 full := r.prev == nil || len(r.prev) != r.rows
202 for i := 0; i < r.rows; i++ {222 for i := 0; i < r.rows; i++ {
203- if full || forceAll || r.prev[i] != frame[i] {223+ if full || forceAll || hasSelection || r.prev[i] != frame[i] {
204 w.WriteString(MoveTo(i+1, 1))224 w.WriteString(MoveTo(i+1, 1))
225+ w.WriteString("\x1b[0m") // reset all attributes first
205 w.WriteString(SeqClearLine)226 w.WriteString(SeqClearLine)
206 w.WriteString(frame[i])227 w.WriteString(frame[i])
207 }228 }
M internal/tui/theme.go +1 -4
@@ -72,10 +72,7 @@ func (t Theme) PadHighlight(s string, width int) string {
7272 if visible < width {
7373 s += strings.Repeat(" ", width-visible)
7474 }
75- // Emit the background color AFTER the reset via a trailing
76- // erase-to-end-of-line so the highlight extends to the terminal
77- // edge even if the cell count is slightly off.
78- return sgrFG(t.SelectionFG) + sgrBG(t.SelectionBG) + s + "\x1b[K" + reset
75+ return sgrFG(t.SelectionFG) + sgrBG(t.SelectionBG) + s + reset
7976 }
8077
8178 // Bold wraps s in bold SGR.
@@ -72,10 +72,7 @@ func (t Theme) PadHighlight(s string, width int) string {
72 if visible < width {72 if visible < width {
73 s += strings.Repeat(" ", width-visible)73 s += strings.Repeat(" ", width-visible)
74 }74 }
75- // Emit the background color AFTER the reset via a trailing75+ return sgrFG(t.SelectionFG) + sgrBG(t.SelectionBG) + s + reset
76- // erase-to-end-of-line so the highlight extends to the terminal
77- // edge even if the cell count is slightly off.
78- return sgrFG(t.SelectionFG) + sgrBG(t.SelectionBG) + s + "\x1b[K" + reset
79 }76 }
80 77
81 // Bold wraps s in bold SGR.78 // Bold wraps s in bold SGR.

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close