Skip to content

Commit 4b6cf80

Browse files
committed
fix: layout would overflow when when list view width was at specific widths
1 parent defb8f4 commit 4b6cf80

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

src/bubbles/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
146146
m.width = msg.Width
147147
m.height = msg.Height
148148
msg.Height = msg.Height - 1
149+
m.help.Width = msg.Width
149150
m.registryselector, _ = m.registryselector.Update(msg)
150151
m.selectedBlocks, _ = m.selectedBlocks.Update(msg)
151152
m.blocklist, _ = m.blocklist.Update(msg)

src/bubbles/block_list/block_list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
8383
})
8484
}
8585
}
86-
m.list.SetItems(items)
86+
cmd = m.list.SetItems(items)
8787
case tea.WindowSizeMsg:
8888
m.list.SetWidth((msg.Width-config.SidebarWidth)/2 - 4)
89+
m.list.Styles.HelpStyle = lipgloss.NewStyle().Width((msg.Width-config.SidebarWidth)/2 - 4)
8990
m.list.SetHeight(msg.Height - 2)
9091
return m, nil
9192
case Blocks:
@@ -100,13 +101,11 @@ func (m Model) View() string {
100101
var s string
101102
if m.focus {
102103
s += lipgloss.NewStyle().
103-
Width(m.list.Width()).
104104
BorderStyle(lipgloss.RoundedBorder()).
105105
BorderForeground(lipgloss.Color("140")).
106106
Render(m.list.View())
107107
} else {
108108
s += lipgloss.NewStyle().
109-
Width(m.list.Width()).
110109
BorderStyle(lipgloss.RoundedBorder()).
111110
BorderForeground(lipgloss.Color("240")).
112111
Render(m.list.View())

src/bubbles/key_binding_help/key_binding_help.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type KeyMap struct {
1212
}
1313

1414
func (k KeyMap) ShortHelp() []key.Binding {
15-
return []key.Binding{k.Tab, k.AddNewRegistry, k.DownloadBlocks, k.S, k.P, k.Quit}
15+
return []key.Binding{k.Tab, k.AddNewRegistry, k.DownloadBlocks, k.S, k.P}
1616
}
1717

1818
func (k KeyMap) FullHelp() [][]key.Binding {
@@ -24,26 +24,26 @@ func (k KeyMap) FullHelp() [][]key.Binding {
2424
var Keys = KeyMap{
2525
Tab: key.NewBinding(
2626
key.WithKeys("tab"),
27-
key.WithHelp("tab", "Switch between views"),
27+
key.WithHelp("tab", "focus next block list panel"),
2828
),
2929
DownloadBlocks: key.NewBinding(
3030
key.WithKeys("ctrl+d"),
31-
key.WithHelp("ctrl+d", "Download blocks"),
31+
key.WithHelp("ctrl+d", "download blocks"),
3232
),
3333
AddNewRegistry: key.NewBinding(
34-
key.WithKeys("ctrl+n"),
35-
key.WithHelp("ctrl+n", "Add new registry"),
34+
key.WithKeys("ctrl+a"),
35+
key.WithHelp("ctrl+a", "add registry"),
3636
),
3737
S: key.NewBinding(
3838
key.WithKeys("s"),
39-
key.WithHelp("s", "Select registry"),
39+
key.WithHelp("s", "focus registries panel"),
4040
),
4141
P: key.NewBinding(
4242
key.WithKeys("p"),
43-
key.WithHelp("p", "Edit category paths"),
43+
key.WithHelp("p", "focus categories panel"),
4444
),
4545
Quit: key.NewBinding(
4646
key.WithKeys("ctrl+c"),
47-
key.WithHelp("ctrl+c", "Quit"),
47+
key.WithHelp("ctrl+c", "quit"),
4848
),
4949
}

src/bubbles/selected_block_list/selected_block_list.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
type Model struct {
14-
listView list.Model
15-
blocks []manifest.Block
16-
focus bool
14+
list list.Model
15+
blocks []manifest.Block
16+
focus bool
1717
}
1818

1919
func New() Model {
@@ -29,8 +29,8 @@ func New() Model {
2929
}
3030

3131
return Model{
32-
listView: list,
33-
blocks: []manifest.Block{},
32+
list: list,
33+
blocks: []manifest.Block{},
3434
}
3535
}
3636

@@ -46,11 +46,11 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
4646
switch msg.Type {
4747
case tea.KeyBackspace:
4848

49-
listHasItems := m.listView.Items() != nil && len(m.listView.Items()) > 0
49+
listHasItems := m.list.Items() != nil && len(m.list.Items()) > 0
5050
if !listHasItems {
5151
return m, nil
5252
}
53-
selectedItem := m.listView.SelectedItem().(block_list.ListItem)
53+
selectedItem := m.list.SelectedItem().(block_list.ListItem)
5454
var blocks []manifest.Block
5555
for _, block := range m.blocks {
5656
if block.Name != selectedItem.Name {
@@ -59,7 +59,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
5959
}
6060
return m, block_list.UpdateBlocks(blocks)
6161
case tea.KeyEnter:
62-
listHasItems := m.listView.Items() != nil && len(m.listView.Items()) > 0
62+
listHasItems := m.list.Items() != nil && len(m.list.Items()) > 0
6363
if !listHasItems {
6464
return m, nil
6565
}
@@ -76,38 +76,37 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
7676
})
7777

7878
}
79-
m.listView.SetItems(items)
79+
cmd = m.list.SetItems(items)
8080
return m, cmd
8181

8282
case tea.WindowSizeMsg:
8383
margin := 4
8484
if msg.Width%2 != 0 {
8585
margin = 3
8686
}
87-
m.listView.SetWidth((msg.Width-config.SidebarWidth)/2 - margin)
88-
m.listView.SetHeight(msg.Height - 2)
87+
m.list.SetWidth((msg.Width-config.SidebarWidth)/2 - margin)
88+
m.list.Styles.HelpStyle = lipgloss.NewStyle().Width((msg.Width-config.SidebarWidth)/2 - margin)
89+
m.list.SetHeight(msg.Height - 2)
8990
return m, nil
9091

9192
}
9293

93-
m.listView, cmd = m.listView.Update(msg)
94+
m.list, cmd = m.list.Update(msg)
9495
cmds = append(cmds, cmd)
9596
return m, tea.Batch(cmds...)
9697
}
9798

9899
func (m Model) View() string {
99100
if m.focus {
100101
return lipgloss.NewStyle().
101-
Width(m.listView.Width()).
102102
BorderStyle(lipgloss.RoundedBorder()).
103103
BorderForeground(lipgloss.Color("140")).
104-
Render(m.listView.View())
104+
Render(m.list.View())
105105
} else {
106106
return lipgloss.NewStyle().
107-
Width(m.listView.Width()).
108107
BorderStyle(lipgloss.RoundedBorder()).
109108
BorderForeground(lipgloss.Color("240")).
110-
Render(m.listView.View())
109+
Render(m.list.View())
111110
}
112111
}
113112

@@ -120,5 +119,5 @@ func (m *Model) Blur() {
120119
}
121120

122121
func (m *Model) SetHeight(height int) {
123-
m.listView.SetHeight(height - 2)
122+
m.list.SetHeight(height - 2)
124123
}

0 commit comments

Comments
 (0)