jesseduffield.lazygit/pkg/gui/controllers/helpers
Stefan Haller b96b8a9753 Add RefreshBlockingInput to buffer keypresses until a refresh has landed
A refresh from the UI thread returns immediately and applies its model
and view updates as queued UI-thread callbacks. A key pressed before
those have run is handled against the stale, pre-refresh state. For most
keys that's harmless, but some handlers turn that state into git
commands: pressing space twice in quick succession in the staging panel
builds the second patch from the already-applied diff and fails with
'patch does not apply', because the refresh after the first press is
what moves the selection to the next stageable hunk.

Notably, this is not just a regression of the recent change that made
UI-thread refreshes non-blocking; the window was merely much narrower
before. A blocking refresh parked the UI thread while the scopes'
bounces were queued, and the event loop drains pending keyboard input
with priority over queued user events, so a key pressed during the
blocked window still beat the queued state updates. The guarantee that
the next keypress sees post-refresh state had already ended when the
scopes' state updates moved from worker-side mutex-guarded writes to
UI-thread bounces.

Fix it with the input-blocking mechanism we already use for commit
surgery, exposed as a new RefreshBlockingInput entry point: it begins
blocking events synchronously in the calling handler, and ends the
block from a callback that the finishing step queues behind the
refresh's own updates. Keys pressed while the refresh is in flight are
buffered and replayed, in order, against the fully refreshed state;
since a replayed key's handler re-enters this same path, a burst of
keypresses applies sequentially, each one seeing the previous one's
refresh. Unlike the old blocking refreshes, this doesn't freeze the UI
thread: rendering, spinners, resizing, and mouse scrolling keep working
while input is withheld.

Blocking input is opt-in per call site rather than the default for all
UI-thread refreshes, because most refreshes (the focus-in and startup
refreshes, say) don't produce state that the next keypress depends on,
and blocking on them would delay typing for no reason. It should also be
limited to quick, narrow-scoped refreshes: a full refresh, or any scope
that pulls in COMMITS, can take very long in large repos and should
usually not hold up input.

The staging panel's stage/discard/edit-hunk refreshes use it now.
2026-07-22 08:31:11 +02:00
..
amend_helper.go Allow passing refresh scope to WithGpgHandling 2025-03-24 08:41:58 +01:00
app_status_helper.go Render the app status in a single background render loop 2026-07-17 15:55:01 +02:00
bisect_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
branches_helper.go Don't auto-forward branches when the repo was switched during the fetch 2026-07-20 17:07:39 +02:00
cherry_pick_helper.go Run the sync commit-surgery ops on a worker with input blocked 2026-07-17 12:32:32 +02:00
commits_helper.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
commits_helper_test.go Remove hard line breaks when rewording commits 2024-03-09 10:00:44 +01:00
confirmation_helper.go Remove the now-dead PopupMutex 2026-07-17 12:35:54 +02:00
credentials_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
diff_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
files_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
fixup_helper.go Suppress command logs for git calls related to the ctrl+f command 2026-07-19 19:22:48 +02:00
fixup_helper_test.go Ignore fixup commits for a found base commit when doing ctrl-f 2026-01-24 16:04:35 +01:00
gpg_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
helpers.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
host_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
inline_status_helper.go Update comments that still describe the removed blocking refresh mode 2026-07-21 22:23:58 +02:00
menu_key.go Use a slice of keys for each binding 2026-05-25 15:18:18 +02:00
merge_and_rebase_helper.go Check for exec todos on the UI thread 2026-07-17 12:35:54 +02:00
merge_conflicts_helper.go Refresh the merge conflicts state on the UI thread 2026-07-17 12:35:54 +02:00
mode_helper.go Make RefreshOptions.Then a func() error, queue it via OnUIThread 2026-07-07 18:09:33 +02:00
patch_building_helper.go Show renamed files in the custom patch builder 2026-07-04 13:05:09 +02:00
record_directory_helper.go split context common from helper common 2023-04-30 13:19:53 +10:00
refresh_helper.go Add RefreshBlockingInput to buffer keypresses until a refresh has landed 2026-07-22 08:31:11 +02:00
refresh_helper_test.go Restore commit selection even when the commit's TODO status changed 2026-06-23 09:20:05 +02:00
refs_helper.go Show the inline status again when checking out a newly created remote branch 2026-07-21 22:23:57 +02:00
repos_helper.go Refuse a repo switch while a foreground operation is in flight 2026-07-07 18:09:33 +02:00
search_helper.go Cleanup: remove unnecessary function Label() 2026-04-30 22:14:26 +02:00
signal_handling.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
signal_handling_windows.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
snake_helper.go Bump gocui and adapt lazygit code 2024-12-01 10:40:08 +01:00
staging_helper.go Add user config to use hunk mode by default when entering staging view 2025-07-04 19:41:40 +02:00
sub_commits_helper.go Remove refresh mutexes made redundant by bouncing 2026-07-07 18:09:33 +02:00
suggestions_helper.go Hold the file-path suggestions trie outside the model 2026-07-17 12:35:54 +02:00
suspend_resume_helper.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
tags_helper.go Convert keybinding fields to Keybinding 2026-05-25 15:32:47 +02:00
update_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
upstream_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
upstream_helper_test.go Standardise on using lo for slice functions 2023-07-30 18:51:23 +10:00
view_helper.go standardise helper args 2023-04-30 13:19:53 +10:00
window_arrangement_helper.go Add gui.shrinkSidePanelsToContent option 2026-07-03 19:25:01 +02:00
window_arrangement_helper_test.go Add gui.shrinkSidePanelsToContent option 2026-07-03 19:25:01 +02:00
window_helper.go Drive the side panel layout from gui.sidePanels 2026-06-23 14:15:18 +02:00
working_tree_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
worktree_helper.go Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
worktree_helper_test.go Add helper to compute candidate worktree parent directories 2026-07-03 18:53:05 +02:00