Skip to content

Commit 83468d0

Browse files
committed
fix: update list rendering in git, bookmarks and custom commands modals
Previous rendering code relied on rendering full string (including the bg style) over the modal window box but the new system is only rendering to the relevant areas while leaving some gaps. Fixed using AddFill for the whole area and calling AddDraw on skip lines. #535
1 parent 1b1aa46 commit 83468d0

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

internal/ui/bookmarks/bookmarks.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (m itemScrollMsg) SetDelta(delta int, horizontal bool) tea.Msg {
4646

4747
type menuStyles struct {
4848
title lipgloss.Style
49-
subtitle lipgloss.Style
5049
shortcut lipgloss.Style
5150
dimmed lipgloss.Style
5251
selected lipgloss.Style
@@ -95,7 +94,6 @@ type Model struct {
9594
cancelFilterKey key.Binding
9695
acceptFilterKey key.Binding
9796
title string
98-
subtitle string
9997
}
10098

10199
func (m *Model) ShortHelp() []key.Binding {
@@ -481,9 +479,6 @@ func (m *Model) ViewRect(dl *render.DisplayContext, box layout.Box) {
481479
menuWidth := max(contentWidth+2, 0)
482480
menuHeight := max(contentHeight+2, 0)
483481
frame := box.Center(menuWidth, menuHeight)
484-
if len(m.visibleItems()) == 0 {
485-
dl.AddFill(frame.R.Inset(1), ' ', lipgloss.NewStyle(), render.ZMenuContent)
486-
}
487482
if frame.R.Dx() <= 0 || frame.R.Dy() <= 0 {
488483
return
489484
}
@@ -493,12 +488,16 @@ func (m *Model) ViewRect(dl *render.DisplayContext, box layout.Box) {
493488
if contentBox.R.Dx() <= 0 || contentBox.R.Dy() <= 0 {
494489
return
495490
}
491+
window.AddFill(contentBox.R, ' ', m.menuStyles.text, render.ZMenuContent)
496492

497493
borderBase := lipgloss.NewStyle().Width(contentBox.R.Dx()).Height(contentBox.R.Dy()).Render("")
498494
window.AddDraw(frame.R, m.menuStyles.border.Render(borderBase), render.ZMenuBorder)
499495

500496
titleBox, contentBox := contentBox.CutTop(1)
501-
window.AddDraw(titleBox.R, m.menuStyles.title.Render(m.title), render.ZMenuContent)
497+
dl.
498+
Text(titleBox.R.Min.X, titleBox.R.Min.Y, render.ZMenuContent).
499+
Styled(m.title, m.menuStyles.title).
500+
Done()
502501

503502
_, contentBox = contentBox.CutTop(1)
504503
remoteBox, contentBox := contentBox.CutTop(1)
@@ -523,11 +522,12 @@ func (m *Model) renderRemotes(dl *render.DisplayContext, lineBox layout.Box) {
523522
if lineBox.R.Dx() <= 0 || lineBox.R.Dy() <= 0 {
524523
return
525524
}
525+
dl.AddFill(lineBox.R, ' ', m.menuStyles.text, render.ZMenuContent)
526526
windowedDl := dl.Window(lineBox.R, render.ZMenuContent)
527527

528528
// Render above menu content
529529
tb := windowedDl.Text(lineBox.R.Min.X, lineBox.R.Min.Y, render.ZMenuContent+1).
530-
Space(1).
530+
Styled(" ", m.menuStyles.text).
531531
Styled("Remotes: ", m.remoteStyles.promptStyle)
532532

533533
if len(m.remoteNames) == 0 {
@@ -540,7 +540,7 @@ func (m *Model) renderRemotes(dl *render.DisplayContext, lineBox layout.Box) {
540540
if idx == m.selectedRemoteIdx {
541541
style = m.remoteStyles.selectedStyle
542542
}
543-
tb.Clickable(remoteName, style, SelectRemoteMsg{Index: idx}).Space(1)
543+
tb.Clickable(remoteName, style, SelectRemoteMsg{Index: idx}).Styled(" ", m.menuStyles.text)
544544
}
545545

546546
tb.Done()
@@ -586,7 +586,6 @@ func NewModel(c *context.MainContext, current *jj.Commit, commitIds []string) *M
586586
cancelFilterKey: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
587587
acceptFilterKey: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "apply filter")),
588588
title: "Bookmark Operations",
589-
subtitle: " ",
590589
allItems: make([]item, 0),
591590
}
592591

@@ -606,7 +605,6 @@ func createMenuStyles(prefix string) menuStyles {
606605
}
607606
return menuStyles{
608607
title: common.DefaultPalette.Get(prefix+"menu title").Padding(0, 1, 0, 1),
609-
subtitle: common.DefaultPalette.Get(prefix+"menu subtitle").Padding(1, 0, 0, 1),
610608
selected: common.DefaultPalette.Get(prefix + "menu selected"),
611609
matched: common.DefaultPalette.Get(prefix + "menu matched"),
612610
dimmed: common.DefaultPalette.Get(prefix + "menu dimmed"),
@@ -870,7 +868,8 @@ func renderItem(dl *render.DisplayContext, rect cellbuf.Rectangle, width int, st
870868
descLine := descStyle.Render(desc)
871869
descLine = lipgloss.PlaceHorizontal(width+2, 0, descLine, lipgloss.WithWhitespaceBackground(titleStyle.GetBackground()))
872870

873-
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine)
871+
spacerLine := styles.text.Width(width + 2).Render("")
872+
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine, spacerLine)
874873
if content == "" {
875874
return
876875
}

internal/ui/custom_commands/custom_commands.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func (m itemScrollMsg) SetDelta(delta int, horizontal bool) tea.Msg {
6666

6767
type styles struct {
6868
title lipgloss.Style
69-
subtitle lipgloss.Style
7069
shortcut lipgloss.Style
7170
dimmed lipgloss.Style
7271
selected lipgloss.Style
@@ -234,12 +233,16 @@ func (m *Model) ViewRect(dl *render.DisplayContext, box layout.Box) {
234233
if contentBox.R.Dx() <= 0 || contentBox.R.Dy() <= 0 {
235234
return
236235
}
236+
window.AddFill(contentBox.R, ' ', m.styles.text, render.ZMenuContent)
237237

238238
borderBase := lipgloss.NewStyle().Width(contentBox.R.Dx()).Height(contentBox.R.Dy()).Render("")
239239
window.AddDraw(frame.R, m.styles.border.Render(borderBase), render.ZMenuBorder)
240240

241241
titleBox, contentBox := contentBox.CutTop(1)
242-
window.AddDraw(titleBox.R, m.styles.title.Render("Custom Commands"), render.ZMenuContent)
242+
dl.
243+
Text(titleBox.R.Min.X, titleBox.R.Min.Y, render.ZMenuContent).
244+
Styled("Custom Commands", m.styles.title).
245+
Done()
243246

244247
_, contentBox = contentBox.CutTop(1)
245248
filterBox, contentBox := contentBox.CutTop(1)
@@ -302,7 +305,6 @@ func createStyles(prefix string) styles {
302305
}
303306
return styles{
304307
title: common.DefaultPalette.Get(prefix+"menu title").Padding(0, 1, 0, 1),
305-
subtitle: common.DefaultPalette.Get(prefix+"menu subtitle").Padding(1, 0, 0, 1),
306308
selected: common.DefaultPalette.Get(prefix + "menu selected"),
307309
matched: common.DefaultPalette.Get(prefix + "menu matched"),
308310
dimmed: common.DefaultPalette.Get(prefix + "menu dimmed"),
@@ -496,7 +498,8 @@ func renderItem(dl *render.DisplayContext, rect cellbuf.Rectangle, width int, st
496498
descLine := descStyle.Render(desc)
497499
descLine = lipgloss.PlaceHorizontal(width+2, 0, descLine, lipgloss.WithWhitespaceBackground(titleStyle.GetBackground()))
498500

499-
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine)
501+
spacerLine := styles.text.Width(width + 2).Render("")
502+
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine, spacerLine)
500503
if content == "" {
501504
return
502505
}

internal/ui/git/git.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func (m itemScrollMsg) SetDelta(delta int, horizontal bool) tea.Msg {
7171

7272
type menuStyles struct {
7373
title lipgloss.Style
74-
subtitle lipgloss.Style
7574
shortcut lipgloss.Style
7675
dimmed lipgloss.Style
7776
selected lipgloss.Style
@@ -119,7 +118,6 @@ type Model struct {
119118
cancelFilterKey key.Binding
120119
acceptFilterKey key.Binding
121120
title string
122-
subtitle string
123121
}
124122

125123
func (m *Model) ShortHelp() []key.Binding {
@@ -156,7 +154,7 @@ func (m *Model) cycleRemotes(step int) tea.Cmd {
156154
m.selectedRemoteIdx = len(m.remoteNames) - 1
157155
}
158156

159-
// Remotes are rendered via TextBuilder in ViewRect, no need to update subtitle
157+
// Remotes are rendered via TextBuilder in ViewRect
160158
m.items = m.createMenuItems()
161159
m.applyFilters(false)
162160
return nil
@@ -305,9 +303,6 @@ func (m *Model) ViewRect(dl *render.DisplayContext, box layout.Box) {
305303
menuWidth := max(contentWidth+2, 0)
306304
menuHeight := max(contentHeight+2, 0)
307305
frame := box.Center(menuWidth, menuHeight)
308-
if len(m.visibleItems()) == 0 {
309-
dl.AddFill(frame.R.Inset(1), ' ', lipgloss.NewStyle(), render.ZMenuContent)
310-
}
311306
if frame.R.Dx() <= 0 || frame.R.Dy() <= 0 {
312307
return
313308
}
@@ -317,12 +312,16 @@ func (m *Model) ViewRect(dl *render.DisplayContext, box layout.Box) {
317312
if contentBox.R.Dx() <= 0 || contentBox.R.Dy() <= 0 {
318313
return
319314
}
315+
window.AddFill(contentBox.R, ' ', m.menuStyles.text, render.ZMenuContent)
320316

321317
borderBase := lipgloss.NewStyle().Width(contentBox.R.Dx()).Height(contentBox.R.Dy()).Render("")
322318
window.AddDraw(frame.R, m.menuStyles.border.Render(borderBase), render.ZMenuBorder)
323319

324320
titleBox, contentBox := contentBox.CutTop(1)
325-
window.AddDraw(titleBox.R, m.menuStyles.title.Render(m.title), render.ZMenuContent)
321+
dl.
322+
Text(titleBox.R.Min.X, titleBox.R.Min.Y, render.ZMenuContent).
323+
Styled(m.title, m.menuStyles.title).
324+
Done()
326325

327326
_, contentBox = contentBox.CutTop(1)
328327
remoteBox, contentBox := contentBox.CutTop(1)
@@ -351,7 +350,7 @@ func (m *Model) renderRemotes(dl *render.DisplayContext, lineBox layout.Box) {
351350

352351
// Render above menu content
353352
tb := windowedDl.Text(lineBox.R.Min.X, lineBox.R.Min.Y, render.ZMenuContent+1).
354-
Space(1).
353+
Styled(" ", m.menuStyles.text).
355354
Styled("Remotes: ", m.remoteStyles.promptStyle)
356355

357356
if len(m.remoteNames) == 0 {
@@ -364,7 +363,7 @@ func (m *Model) renderRemotes(dl *render.DisplayContext, lineBox layout.Box) {
364363
if idx == m.selectedRemoteIdx {
365364
style = m.remoteStyles.selectedStyle
366365
}
367-
tb.Clickable(remoteName, style, SelectRemoteMsg{Index: idx}).Space(1)
366+
tb.Clickable(remoteName, style, SelectRemoteMsg{Index: idx}).Styled(" ", m.menuStyles.text)
368367
}
369368

370369
tb.Done()
@@ -424,7 +423,6 @@ func NewModel(c *context.MainContext, revisions jj.SelectedRevisions) *Model {
424423
cancelFilterKey: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
425424
acceptFilterKey: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "apply filter")),
426425
title: "Git Operations",
427-
subtitle: " ",
428426
}
429427

430428
items := m.createMenuItems()
@@ -446,7 +444,6 @@ func createMenuStyles(prefix string) menuStyles {
446444
}
447445
return menuStyles{
448446
title: common.DefaultPalette.Get(prefix+"menu title").Padding(0, 1, 0, 1),
449-
subtitle: common.DefaultPalette.Get(prefix+"menu subtitle").Padding(1, 0, 0, 1),
450447
selected: common.DefaultPalette.Get(prefix + "menu selected"),
451448
matched: common.DefaultPalette.Get(prefix + "menu matched"),
452449
dimmed: common.DefaultPalette.Get(prefix + "menu dimmed"),
@@ -645,7 +642,8 @@ func renderItem(dl *render.DisplayContext, rect cellbuf.Rectangle, width int, st
645642
descLine := descStyle.Render(desc)
646643
descLine = lipgloss.PlaceHorizontal(width+2, 0, descLine, lipgloss.WithWhitespaceBackground(titleStyle.GetBackground()))
647644

648-
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine)
645+
spacerLine := styles.text.Width(width + 2).Render("")
646+
content := lipgloss.JoinVertical(lipgloss.Left, titleLine, descLine, spacerLine)
649647
if content == "" {
650648
return
651649
}

0 commit comments

Comments
 (0)