mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-02 09:21:40 +02:00
bd7fabef1f
Before this commit, we had pkg/integration/tests/submodule/add.go failing with a panic. I'm pretty sure the issue is this: we're now calling quite a few GetDisabledReason calls on each layout() call, and if a background thread happens to update a model slice while we're doing this, we can end up with a selection index that's now out of bounds because it hasn't been clamped to match the new list length. Specifically, here we had the selected index being -1 (the list starts empty and somehow the value is -1 in this case) and then the list gets a new submodule so the length is now 1, but the list cursor doesn't know about this so remains on the old value. Then we confirm the length is greater than zero and try to get the selected submodule and get an out of bounds error. This commit fixes the issue by clamping the selected index whenever we get the length of the list so that it stays in-sync. This is not a perfect solution because the length can change at any time, but it seems to reliably fix the test, and using mutexes didn't seem to make a difference. Note that we're swapping the order of IFileTree and IListCursor in the file tree view model to ensure that the list cursor's Len() method is called (which performs the clamping). Also, comment from the PR: This 'trait' pattern we're using is convenient but can lead to awkward situations. In this case we have both the list view model and the (embedded) list cursor with a Len() method. The list cursor Len() method just calls the list view model Len() method. But I wanted to make it that the list view model now calls ClampSelection() on the list cursor whenever it obtains the length. This will cause an infinite loop because ClampSelection() internally calls Len() (which calls the list view model's Len() method which in turn calls ClampSelection() again, etc). The only reason we were passing the list view model into the list cursor was to supply the length method, so now we're just doing that directly, and letting the list view model delegate the Len() call to the list cursor, which now itself calls ClampSelection. |
||
---|---|---|
.. | ||
traits | ||
base_context.go | ||
branches_context.go | ||
commit_files_context.go | ||
commit_message_context.go | ||
confirmation_context.go | ||
context_common.go | ||
context.go | ||
dynamic_title_builder.go | ||
filtered_list_view_model.go | ||
filtered_list.go | ||
history_trait.go | ||
list_context_trait.go | ||
list_renderer_test.go | ||
list_renderer.go | ||
list_view_model.go | ||
local_commits_context.go | ||
menu_context.go | ||
merge_conflicts_context.go | ||
parent_context_mgr.go | ||
patch_explorer_context.go | ||
reflog_commits_context.go | ||
remote_branches_context.go | ||
remotes_context.go | ||
search_trait.go | ||
setup.go | ||
simple_context.go | ||
stash_context.go | ||
sub_commits_context.go | ||
submodules_context.go | ||
suggestions_context.go | ||
tags_context.go | ||
view_trait.go | ||
working_tree_context.go | ||
worktrees_context.go |