Skip to content

Commit fed41f0

Browse files
committed
fix: eliminate ghost text across all TUI views with padAllLines
Root cause fix: instead of padding individual lines (easy to miss), add padAllLines() that pads every line in the final View() output to the terminal width. Applied to all 6 View returns across selector, snapshot editor, and macOS selector — prevents ghost text from previously rendered longer lines bleeding through on tab switches, search, and empty states.
1 parent 6026196 commit fed41f0

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

internal/ui/macos_selector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (m MacOSSelectorModel) View() string {
327327
lines = append(lines, "")
328328
lines = append(lines, helpStyle.Render("Tab/←→: switch • ↑↓: navigate • Space: toggle • a: all • Enter: confirm • q: quit"))
329329

330-
return strings.Join(lines, "\n")
330+
return padAllLines(strings.Join(lines, "\n"), m.width)
331331
}
332332

333333
func (m MacOSSelectorModel) macosConfirmationView() string {
@@ -395,7 +395,7 @@ func (m MacOSSelectorModel) macosConfirmationView() string {
395395
content.WriteString("\n")
396396
content.WriteString(instructionStyle.Render("[Esc] Go Back"))
397397

398-
return boxStyle.Render(content.String())
398+
return padAllLines(boxStyle.Render(content.String()), m.width)
399399
}
400400

401401
// SelectedPreferences returns the list of preferences the user enabled.

internal/ui/selector.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,20 @@ func padLine(line string, width int) string {
588588
return line + strings.Repeat(" ", width-visualWidth)
589589
}
590590

591+
// padAllLines pads every line in a rendered view to the given terminal width.
592+
// This is the root-cause fix for ghost text: instead of padding individual
593+
// lines (easy to miss), call this once on the final View() output.
594+
func padAllLines(s string, width int) string {
595+
if width <= 0 {
596+
return s
597+
}
598+
lines := strings.Split(s, "\n")
599+
for i, line := range lines {
600+
lines[i] = padLine(line, width)
601+
}
602+
return strings.Join(lines, "\n")
603+
}
604+
591605
func (m SelectorModel) View() string {
592606
if m.showConfirmation {
593607
return m.confirmationView()
@@ -667,7 +681,7 @@ func (m SelectorModel) View() string {
667681
lines = append(lines, "")
668682
lines = append(lines, helpStyle.Render("Tab/←→: switch • ↑↓: navigate • Space: toggle • /: search • a: all • Enter: confirm • q: quit"))
669683

670-
return strings.Join(lines, "\n")
684+
return padAllLines(strings.Join(lines, "\n"), m.width)
671685
}
672686

673687
func (m SelectorModel) confirmationView() string {
@@ -788,7 +802,7 @@ func (m SelectorModel) confirmationView() string {
788802
content.WriteString("\n")
789803
content.WriteString(instructionStyle.Render("[Esc] Go Back"))
790804

791-
return boxStyle.Render(content.String())
805+
return padAllLines(boxStyle.Render(content.String()), m.width)
792806
}
793807

794808
func (m SelectorModel) viewSearch() string {
@@ -944,7 +958,7 @@ func (m SelectorModel) viewSearch() string {
944958
lines = append(lines, "")
945959
lines = append(lines, helpStyle.Render("↑↓: navigate • Space: toggle • Esc: exit search • Enter: confirm"))
946960

947-
return strings.Join(lines, "\n")
961+
return padAllLines(strings.Join(lines, "\n"), m.width)
948962
}
949963

950964
func (m SelectorModel) Selected() map[string]bool {

internal/ui/snapshot_editor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func (m SnapshotEditorModel) View() string {
477477
visibleItems := m.getVisibleItems()
478478

479479
if len(tab.items) == 0 {
480-
lines = append(lines, padLine(descStyle.Render(" No items"), m.width))
480+
lines = append(lines, descStyle.Render(" No items"))
481481
} else {
482482
scrollOffset := m.scrollOffset
483483
if scrollOffset > len(tab.items)-visibleItems {
@@ -542,7 +542,7 @@ func (m SnapshotEditorModel) View() string {
542542
lines = append(lines, "")
543543
lines = append(lines, helpStyle.Render("/: search online • +: add manually • Space: toggle • a: all • Tab/←→: switch • Enter: confirm • q: cancel"))
544544

545-
return strings.Join(lines, "\n")
545+
return padAllLines(strings.Join(lines, "\n"), m.width)
546546
}
547547

548548
func (m SnapshotEditorModel) viewSearch() string {
@@ -614,7 +614,7 @@ func (m SnapshotEditorModel) viewSearch() string {
614614
lines = append(lines, "")
615615
lines = append(lines, helpStyle.Render("↑↓: navigate • Space/Enter: toggle/add • Esc: exit search"))
616616

617-
return strings.Join(lines, "\n")
617+
return padAllLines(strings.Join(lines, "\n"), m.width)
618618
}
619619

620620
func (m SnapshotEditorModel) toggleOrAddSearchItem() (SnapshotEditorModel, tea.Cmd) {

0 commit comments

Comments
 (0)