ui/text: handle stop and scroll immediately

In case an event is returned, don't aggregate state changes in Next.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-08 00:06:31 +02:00
parent 2292fd0c63
commit 84cd3fcdca
2 changed files with 14 additions and 13 deletions
+4
View File
@@ -222,6 +222,10 @@ func (s *Scroll) val(p f32.Point) float32 {
}
}
func (s *Scroll) Active() bool {
return s.flinger.Active()
}
func (f *flinger) Init(now time.Time, v0 float32) {
f.t0 = now
f.v0 = v0
+10 -13
View File
@@ -96,7 +96,6 @@ func (e *Editor) Next() (EditorEvent, bool) {
e.scrollOff.Y += sdist
soff = e.scrollOff.Y
}
scrollTo := false
for {
evt, ok := e.clicker.Next(e.Inputs)
if !ok {
@@ -105,16 +104,20 @@ func (e *Editor) Next() (EditorEvent, bool) {
switch {
case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
evt.Type == gesture.TypeClick && evt.Source == pointer.Touch:
scrollTo = true
e.blinkStart = e.Config.Now
e.moveCoord(image.Point{
X: int(math.Round(float64(evt.Position.X))),
Y: int(math.Round(float64(evt.Position.Y))),
})
e.requestFocus = true
if !e.scroller.Active() {
e.scrollToCaret()
}
}
}
stop := (sdist > 0 && soff >= smax) || (sdist < 0 && soff <= smin)
if (sdist > 0 && soff >= smax) || (sdist < 0 && soff <= smin) {
e.scroller.Stop()
}
for {
ke, ok := e.Inputs.Next(e)
if !ok {
@@ -134,24 +137,18 @@ func (e *Editor) Next() (EditorEvent, bool) {
}
}
if e.command(ke) {
stop = true
scrollTo = true
e.scrollToCaret()
e.scroller.Stop()
}
case key.EditEvent:
stop = true
scrollTo = true
e.scrollToCaret()
e.scroller.Stop()
e.append(ke.Text)
}
if e.rr.Changed() {
return ChangeEvent{}, true
}
}
if sdist == 0 && scrollTo {
e.scrollToCaret()
}
if stop {
e.scroller.Stop()
}
return nil, false
}