Skip to content

SearchView: use FilterModel - #406

Open
danirabbit wants to merge 6 commits into
mainfrom
danirabbit/searchview-filtermodel
Open

danirabbit wants to merge 6 commits into
mainfrom
danirabbit/searchview-filtermodel

Conversation

@danirabbit

@danirabbit danirabbit commented Oct 29, 2026 •

Copy link
Copy Markdown
Member
  • Replace listbox.filter_func with a filter model
  • Take the query as a string instead of holding a reference to a UI element
  • When query changes, compare to the old query to see if we can filter the previous results and go faster
  • Use GLib's match_string so we can also get results regardless of accent usage

@danirabbit
danirabbit requested a review from a team October 29, 2026 20:20

@leolost2605 leolost2605 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look at Gtk.StringFilter?

@danirabbit

Copy link
Copy Markdown
Member Author

@leolost2605 I opened a branch here using StringFilter instead. The only thing is I'm not sure how we can also update pattern so the search result label gets marked up

@leolost2605 leolost2605 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't have a good idea for that either. We could just bind the query property to the pattern of every row. Right now that's a bit problematic because we actually have to do it for every row but eventually we could bind in list_view.bind and unbind in list_view.unbind which should scale much better and make the performance good AFAICT (though with the limited amout of search options performance shouldn't be bad right now either).

I wouldn't mind the current way it's done but unfortunately CustomFilter is always a bit tricky and in this case it would leak memory (see review comment)

Comment thread src/SearchView.vala
private bool filter_func (Gtk.ListBoxRow listbox_row) {
var search_text = search_entry.text;
if (search_text == "" || search_text == null) {
private bool filter_func (Object object) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the filter func is not static we will get a reference cycle :(

us -> filter model -> filter -> callback target (= us)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants