fix: reset cursor_x when clearing filter on Escape - #199
Conversation
Hitting Escape did not reset cursor_x to 0, which made get_char_idx return a wrong index into the filter string and caused filter.remove(idx) to panic with "cannot remove a char from the end of a string" on backspace.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughStopping filtering without saving now resets the selector’s horizontal cursor position to ChangesFiltering cursor behavior
Estimated code review effort: 1 (Trivial) | ~2 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR preserves the filter cursor invariant when clearing a Select filter.
Confidence Score: 5/5The PR appears safe to merge with no actionable issues identified. Clearing the filter now also resets its cursor position, keeping cursor state within the empty filter’s valid bounds before the next filtering session. Important Files Changed
Reviews (1): Last reviewed commit: "fix: reset cursor_x when clearing filter..." | Re-trigger Greptile |
Problem
In
Select, pressing Escape (handle_stop_filtering(false)) clears the filter string but does not resetcursor_xto 0. On the next filtering session,handle_filter_backspacecallsself.get_char_idx(&self.filter, self.cursor_x - 1)with a stalecursor_x, which returns an index past the end of the (now shorter) filter string, makingself.filter.remove(idx)panic:Observed downstream in mise (
mise runtask picker): type a filter, press Escape, start filtering again, press Backspace → crash.Fix
Reset
cursor_x = 0alongsidefilter.clear()when the filter is not saved, so the cursor state stays consistent with the empty filter string.Summary by CodeRabbit