By ``` openfiles_remove(doc); sidebar_openfiles_add(doc); ``` `iter` is removed/re-added to the store. This invalidates `filter_iter` which has to be re-converted from `iter` to avoid runtime warning.
Fixes runtime error reported in https://github.com/geany/geany/pull/4210#issuecomment-2617024036
(I moved `treesel` assignment up as it makes the code clearer - otherwise it's unrelated to the change made by this patch) You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/4218
-- Commit Summary --
* Re-convert filter_iter after removing/re-adding iter from/to store
-- File Changes --
M src/sidebar.c (14)
-- Patch Links --
https://github.com/geany/geany/pull/4218.patch https://github.com/geany/geany/pull/4218.diff
@b4n approved this pull request.
Not tested, but LGTM
/* we need to re-convert iter->filter_iter as the original filter_iter
+ * becomes invalid after removal and re-addition of doc from/to sidebar */
The root reason is that iter itself changed (which might not be clear here, as it's a pointer to a member of `doc`, and is not directly modified here), so incidentally the filtered one does at well.
have_filter_iter = gtk_tree_model_filter_convert_child_iter_to_iter(
+ GTK_TREE_MODEL_FILTER(filter_model), &filter_iter, iter); + if (have_filter_iter) + gtk_tree_selection_select_iter(treesel, &filter_iter);
Style-wise, I'd drop the `have_filter_iter` variable and move the call in the `if()`, but if that was chosen because the call is long, fair enough.
@techee commented on this pull request.
/* we need to re-convert iter->filter_iter as the original filter_iter
+ * becomes invalid after removal and re-addition of doc from/to sidebar */
The root reason is that iter itself changed (which might not be clear here, as it's a pointer to a member of doc, and is not directly modified here)
Right, I was wondering if `iter` remained the same and didn't notice the pointer to `doc`. I should probably update the comment.
@techee commented on this pull request.
have_filter_iter = gtk_tree_model_filter_convert_child_iter_to_iter(
+ GTK_TREE_MODEL_FILTER(filter_model), &filter_iter, iter); + if (have_filter_iter) + gtk_tree_selection_select_iter(treesel, &filter_iter);
if that was chosen because the call is long, fair enough.
That's exactly the reason - I think it's more readable this way.
@techee pushed 1 commit.
6b41a0e6cdecf7656e290c8ae0c67bb1f7cb6915 Re-convert filter_iter after removing/re-adding iter from/to store
@techee commented on this pull request.
/* we need to re-convert iter->filter_iter as the original filter_iter
+ * becomes invalid after removal and re-addition of doc from/to sidebar */
I should probably update the comment.
Done now.
@b4n approved this pull request.
Merged #4218 into master.
Thank you, works as expected.
github-comments@lists.geany.org