Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrapped content in multi-select #479

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions field_multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (m *MultiSelect[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *MultiSelect[T]) updateViewportHeight() {
// If no height is set size the viewport to the number of options.
if m.height <= 0 {
m.viewport.Height = len(m.options.val)
m.viewport.Height = lipgloss.Height(m.optionsView())
return
}

Expand Down Expand Up @@ -555,13 +555,17 @@ func (m *MultiSelect[T]) optionsView() string {
} else {
sb.WriteString(strings.Repeat(" ", lipgloss.Width(c)))
}
// Calculate width constraints.
prefixWidth := max(lipgloss.Width(styles.SelectedPrefix.String()), lipgloss.Width(styles.UnselectedPrefix.String()))
frameSize := styles.Base.GetHorizontalFrameSize()
contentWidth := m.width - frameSize - lipgloss.Width(c) - prefixWidth

if m.filteredOptions[i].selected {
sb.WriteString(styles.SelectedPrefix.String())
sb.WriteString(styles.SelectedOption.Render(option.Key))
sb.WriteString(styles.SelectedOption.Width(contentWidth).Render(option.Key))
} else {
sb.WriteString(styles.UnselectedPrefix.String())
sb.WriteString(styles.UnselectedOption.Render(option.Key))
sb.WriteString(styles.UnselectedOption.Width(contentWidth).Render(option.Key))
}
if i < len(m.options.val)-1 {
sb.WriteString("\n")
Expand Down
11 changes: 11 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func (g *Group) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
g.WithHeight(max(g.height, min(g.fullHeight(), msg.Height-1)))
g.WithWidth(max(g.width, min(g.fullWidth(), msg.Width-1)))
case nextFieldMsg:
cmds = append(cmds, g.nextField()...)
case prevFieldMsg:
Expand All @@ -290,6 +291,16 @@ func (g *Group) fullHeight() int {
return height
}

// width returns the full width of the group.

Choose a reason for hiding this comment

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

nitpick: change // width to // fullWidth

func (g *Group) fullWidth() int {
width := g.selector.Total()
g.selector.Range(func(_ int, field Field) bool {
width += lipgloss.Width(field.View())
return true
})
return width
}

func (g *Group) getContent() (int, string) {
var fields strings.Builder
offset := 0
Expand Down
Loading