From 09f4ef0bc7864b6752e70306d5449efc3139b81a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 16 May 2024 15:42:30 -0400 Subject: [PATCH] fix(windows): prevent firing multiple window size events On Windows, changing the alt-screen-buffer triggers a window-size-event. This might cause issues with some applications. Cache the last window-size-event and compare before sending it the model. Fixes: https://github.com/charmbracelet/bubbletea/issues/1019 --- key_windows.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/key_windows.go b/key_windows.go index f1ad2d3f90..a5dbfc832c 100644 --- a/key_windows.go +++ b/key_windows.go @@ -22,7 +22,8 @@ func readInputs(ctx context.Context, msgs chan<- Msg, input io.Reader) error { } func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) error { - var ps coninput.ButtonState // keep track of previous mouse state + var ps coninput.ButtonState // keep track of previous mouse state + var ws coninput.WindowBufferSizeEventRecord // keep track of the last window size event for { events, err := coninput.ReadNConsoleInputs(con, 16) if err != nil { @@ -45,10 +46,13 @@ func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) e }) } case coninput.WindowBufferSizeEventRecord: - msgs = append(msgs, WindowSizeMsg{ - Width: int(e.Size.X), - Height: int(e.Size.Y), - }) + if e != ws { + ws = e + msgs = append(msgs, WindowSizeMsg{ + Width: int(e.Size.X), + Height: int(e.Size.Y), + }) + } case coninput.MouseEventRecord: event := mouseEvent(ps, e) if event.Type != MouseUnknown {