Refactor ctx stashing out of exline

This commit is contained in:
Drew DeVault 2019-05-11 13:20:29 -04:00
parent 8fa4583230
commit 72e4b5e2b2
2 changed files with 4 additions and 8 deletions

View File

@ -57,6 +57,8 @@ func (ti *TextInput) Focus(focus bool) {
if focus && ti.ctx != nil { if focus && ti.ctx != nil {
cells := runewidth.StringWidth(string(ti.text[:ti.index])) cells := runewidth.StringWidth(string(ti.text[:ti.index]))
ti.ctx.SetCursor(cells+1, 0) ti.ctx.SetCursor(cells+1, 0)
} else if !focus && ti.ctx != nil {
ti.ctx.HideCursor()
} }
} }

View File

@ -10,7 +10,6 @@ type ExLine struct {
ui.Invalidatable ui.Invalidatable
cancel func() cancel func()
commit func(cmd string) commit func(cmd string)
ctx *ui.Context
input *ui.TextInput input *ui.TextInput
} }
@ -32,7 +31,6 @@ func (ex *ExLine) Invalidate() {
} }
func (ex *ExLine) Draw(ctx *ui.Context) { func (ex *ExLine) Draw(ctx *ui.Context) {
ex.ctx = ctx // gross
ex.input.Draw(ctx) ex.input.Draw(ctx)
} }
@ -45,14 +43,10 @@ func (ex *ExLine) Event(event tcell.Event) bool {
case *tcell.EventKey: case *tcell.EventKey:
switch event.Key() { switch event.Key() {
case tcell.KeyEnter: case tcell.KeyEnter:
if ex.ctx != nil { ex.input.Focus(false)
ex.ctx.HideCursor()
}
ex.commit(ex.input.String()) ex.commit(ex.input.String())
case tcell.KeyEsc, tcell.KeyCtrlC: case tcell.KeyEsc, tcell.KeyCtrlC:
if ex.ctx != nil { ex.input.Focus(false)
ex.ctx.HideCursor()
}
ex.cancel() ex.cancel()
default: default:
return ex.input.Event(event) return ex.input.Event(event)