Skip to content
Myr

fix(windows): prevent firing multiple window size events

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Ayman Bagabas · committed by Ayman Bagabas · parent 920d07b · Browse files · 1 file+9 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: https://github.com/charmbracelet/bubbletea/issues/1019

Diff stats

1 file+9 added−5 removed

  • other:+9 added−5 removed

1 file+9 added−5 removed

modified:key_windows.go+9 added-5 removed
20 unmodified lines
21 return readAnsiInputs(ctx, msgs, localereader.NewReader(input))22}2324func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) error {25 var ps coninput.ButtonState // keep track of previous mouse state25 var ps coninput.ButtonState // keep track of previous mouse state26 var ws coninput.WindowBufferSizeEventRecord // keep track of the last window size event27 for {28 events, err := coninput.ReadNConsoleInputs(con, 16)29 if err != nil {30 return fmt.Errorf("read coninput events: %w", err)
14 unmodified lines
45 Alt: e.ControlKeyState.Contains(coninput.LEFT_ALT_PRESSED | coninput.RIGHT_ALT_PRESSED),46 })47 }48 case coninput.WindowBufferSizeEventRecord:49 if e != ws {50 ws = e48 msgs = append(msgs, WindowSizeMsg{49 Width: int(e.Size.X),50 Height: int(e.Size.Y),51 })51 msgs = append(msgs, WindowSizeMsg{52 Width: int(e.Size.X),53 Height: int(e.Size.Y),54 })55 }56 case coninput.MouseEventRecord:57 event := mouseEvent(ps, e)58 if event.Type != MouseUnknown {59 msgs = append(msgs, event)
282 unmodified lines