From c791f593510d13901733bd5012f79b2ce9fc6fae Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 24 May 2020 12:45:28 +0200 Subject: [PATCH] widget: simplify Editor event flushing Signed-off-by: Elias Naur --- widget/editor.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/widget/editor.go b/widget/editor.go index ebab3919..01b5ddd7 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -98,6 +98,11 @@ func (e *Editor) Events(gtx layout.Context) []EditorEvent { } func (e *Editor) processEvents(gtx layout.Context) { + // Flush events from before the previous Layout. + n := copy(e.events, e.events[e.prevEvents:]) + e.events = e.events[:n] + e.prevEvents = n + if e.shaper == nil { // Can't process events without a shaper. return @@ -234,10 +239,6 @@ func (e *Editor) Focused() bool { // Layout lays out the editor. func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size unit.Value) layout.Dimensions { - // Flush events from before the previous frame. - copy(e.events, e.events[e.prevEvents:]) - e.events = e.events[:len(e.events)-e.prevEvents] - e.prevEvents = len(e.events) textSize := fixed.I(gtx.Px(size)) if e.font != font || e.textSize != textSize { e.invalidate()