Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
fix move in form
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 12, 2022
1 parent 7dc1bcf commit cd852d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tui/form/form.go
Expand Up @@ -159,19 +159,35 @@ func (v *Form) focusPreItem() []tea.Cmd {
}

func (v *Form) idxAfterFocusItem() int {
idx := v.focus + 1
if idx >= len(v.Items) {
idx = 0
idx := v.focus
for {
idx++
if idx >= len(v.Items) {
idx = 0
}
if !v.Items[idx].Hide() {
return idx
}
if idx == v.focus {
return v.focus
}
}
return idx
}

func (v *Form) idxBeforeFocusItem() int {
idx := v.focus - 1
if idx < 0 {
idx = len(v.Items) - 1
idx := v.focus
for {
idx--
if idx < 0 {
idx = len(v.Items) - 1
}
if !v.Items[idx].Hide() {
return idx
}
if idx == v.focus {
return v.focus
}
}
return idx
}

func (v *Form) setFocusItem(idx int, mode FocusMode) []tea.Cmd {
Expand Down
4 changes: 4 additions & 0 deletions tui/node_view.go
Expand Up @@ -2,6 +2,7 @@ package tui

import (
"fmt"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"gohost/gohost"
Expand Down Expand Up @@ -117,6 +118,9 @@ func (v *NodeView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
log.Debug(fmt.Sprintf("node view w %d h %d", m.Width, m.Height))
case tea.KeyMsg:
if key.Matches(m, keys.Esc) {
v.model.switchState(treeViewState)
}
return v.Form.Update(msg)
}
_, cmd := v.Form.Update(msg)
Expand Down

0 comments on commit cd852d7

Please sign in to comment.