commit autocomplete automatically on up/down
This commit is contained in:
parent
556ebcd9c6
commit
6ed2f36928
@ -28,10 +28,16 @@ func (view *Settings) Event(state *ui.State, event vaxis.Event) (processed bool)
|
|||||||
case "Ctrl+c", "Ctrl+d":
|
case "Ctrl+c", "Ctrl+d":
|
||||||
close(ui.Quit)
|
close(ui.Quit)
|
||||||
case "Up":
|
case "Up":
|
||||||
|
if view.index == 3 {
|
||||||
|
view.inputs[2].Update(event)
|
||||||
|
}
|
||||||
if view.index > 0 {
|
if view.index > 0 {
|
||||||
view.index--
|
view.index--
|
||||||
}
|
}
|
||||||
case "Down":
|
case "Down":
|
||||||
|
if view.index == 3 {
|
||||||
|
view.inputs[2].Update(event)
|
||||||
|
}
|
||||||
if view.index < 4 {
|
if view.index < 4 {
|
||||||
view.index++
|
view.index++
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,7 @@ type Input struct {
|
|||||||
Placeholder string
|
Placeholder string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Input) Draw(win vaxis.Window) {
|
func complete(m *Input) (rest string) {
|
||||||
// figure out which thing to complete
|
|
||||||
rest := ""
|
|
||||||
if m.model.String() != "" {
|
if m.model.String() != "" {
|
||||||
for _, comp := range m.AutoComplete {
|
for _, comp := range m.AutoComplete {
|
||||||
if strings.HasPrefix(comp, m.model.String()) {
|
if strings.HasPrefix(comp, m.model.String()) {
|
||||||
@ -26,11 +24,25 @@ func (m *Input) Draw(win vaxis.Window) {
|
|||||||
} else {
|
} else {
|
||||||
rest = m.Placeholder
|
rest = m.Placeholder
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Input) Draw(win vaxis.Window) {
|
||||||
|
// figure out which thing to complete
|
||||||
|
rest := complete(m)
|
||||||
m.model.Draw(win)
|
m.model.Draw(win)
|
||||||
win.New(len(m.model.String()), 0, win.Width, win.Height).Print(vaxis.Segment{Text: rest, Style: vaxis.Style{Foreground: vaxis.IndexColor(8)}})
|
win.New(len(m.model.String()), 0, win.Width, win.Height).Print(vaxis.Segment{Text: rest, Style: vaxis.Style{Foreground: vaxis.IndexColor(8)}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Input) Update(event vaxis.Event) {
|
func (m *Input) Update(event vaxis.Event) {
|
||||||
|
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
|
||||||
|
switch key.String() {
|
||||||
|
case "Up", "Down":
|
||||||
|
if m.model.String() != "" {
|
||||||
|
m.model.SetContent(m.model.String() + complete(m))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
m.model.Update(event)
|
m.model.Update(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user