-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-apply filter when model changes #3058
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,18 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) { | |
} | ||
} | ||
|
||
func (self *SearchHelper) ReApplyFilter(context types.Context) { | ||
state := self.searchState() | ||
if context == state.Context { | ||
filterableContext, ok := context.(types.IFilterableContext) | ||
if ok { | ||
filterableContext.SetSelectedLineIdx(0) | ||
_ = filterableContext.GetView().SetOriginY(0) | ||
filterableContext.ReApplyFilter() | ||
Comment on lines
+235
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we rename the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not reset the filter because there may intermittently be an empty resulting list (I'm thinking of the weirdness that happens when refreshing the files view for example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The files view is not filterable (yet?), so this wouldn't be an issue right now. But I agree, the behavior could be strange in other cases; say you filter the branches list, type so much that no branch shows up, and then the background fetch comes along and refreshes the branches. |
||
} | ||
} | ||
} | ||
|
||
func (self *SearchHelper) RenderSearchStatus(c types.Context) { | ||
if c.GetKey() == context.SEARCH_CONTEXT_KEY { | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package filter_and_search | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var FilterUpdatesWhenModelChanges = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Verify that after deleting a branch the filter is reapplied to show only the remaining branches", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("first commit") | ||
shell.NewBranch("branch-to-delete") | ||
shell.NewBranch("other") | ||
shell.NewBranch("checked-out-branch") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Branches(). | ||
Focus(). | ||
Lines( | ||
Contains("checked-out-branch").IsSelected(), | ||
Contains("other"), | ||
Contains("branch-to-delete"), | ||
Contains("master"), | ||
). | ||
FilterOrSearch("branch"). | ||
Lines( | ||
Contains("branch-to-delete").IsSelected(), | ||
Contains("checked-out-branch"), | ||
). | ||
Press(keys.Universal.Remove). | ||
Tap(func() { | ||
t.ExpectPopup(). | ||
Menu(). | ||
Title(Equals("Delete branch 'branch-to-delete'?")). | ||
Select(Contains("Delete local branch")). | ||
Confirm() | ||
}). | ||
Lines( | ||
Contains("checked-out-branch").IsSelected(), | ||
). | ||
// cancel the filter | ||
PressEscape(). | ||
Lines( | ||
Contains("checked-out-branch").IsSelected(), | ||
Contains("other"), | ||
Contains("master"), | ||
) | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we expose the already existing
applyFilter
instead? As an alternative, what about naming itInvalidateModel
? I'm trying to reduce the amount of redundant code or justifying it for extensibility. Does that make sense to you?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing
applyFilter
publicly would be fine with me (I'd rename it to ReApplyFilter then), but on the other hand the one-line forwarder doesn't bother me much. So no strong opinion here.I wouldn't rename it to
InvalidateModel
though, this would sound misleading to me. MaybeOnModelInvalidated
, but I'm not sure why that's better.The other question is more interesting: should we move some of the logic specific to contexts (e.g. selecting lines etc) from SearchHelper to FilteredListViewModel. The same could be asked for the existing code in
OnPromptContentChanged
. I don't really have much of an opinion here, happy to follow whatever Jesse tells me to do. Personally I'd leave everything the way it is, as that's the least amount of work. 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to leave things where they are for now, but happy to accept a separate PR that does the refactor if anybody's up to it