ui/text: add ChangeEvent and rename Submit to SubmitEvent

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-04 15:06:50 +02:00
parent 252514af9d
commit f1dffa155c
2 changed files with 21 additions and 3 deletions
+8 -3
View File
@@ -59,14 +59,16 @@ type EditorEvent interface {
isEditorEvent()
}
type Submit struct{}
type ChangeEvent struct{}
type SubmitEvent struct{}
const (
blinksPerSecond = 1
maxBlinkDuration = 10 * time.Second
)
func (s Submit) isEditorEvent() {}
func (s ChangeEvent) isEditorEvent() {}
func (s SubmitEvent) isEditorEvent() {}
func (e *Editor) Next() (EditorEvent, bool) {
if cfg := *e.Config; cfg != e.oldCfg {
@@ -126,7 +128,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
}
if e.Submit && (ke.Name == key.NameReturn || ke.Name == key.NameEnter) {
if !ke.Modifiers.Contain(key.ModShift) {
return Submit{}, true
return SubmitEvent{}, true
}
}
if e.command(ke) {
@@ -138,6 +140,9 @@ func (e *Editor) Next() (EditorEvent, bool) {
scrollTo = true
e.append(ke.Text)
}
if e.rr.Changed() {
return ChangeEvent{}, true
}
}
if sdist == 0 && scrollTo {
e.scrollToCaret()