Skip to content

fix: reset cursor_x when clearing filter on Escape - #199

Merged
jdx merged 1 commit into
jdx:mainfrom
macroexpansion:fix/select-escape-cursor-x
Jul 28, 2026
Merged

fix: reset cursor_x when clearing filter on Escape#199
jdx merged 1 commit into
jdx:mainfrom
macroexpansion:fix/select-escape-cursor-x

Conversation

@macroexpansion

@macroexpansion macroexpansion commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Problem

In Select, pressing Escape (handle_stop_filtering(false)) clears the filter string but does not reset cursor_x to 0. On the next filtering session, handle_filter_backspace calls self.get_char_idx(&self.filter, self.cursor_x - 1) with a stale cursor_x, which returns an index past the end of the (now shorter) filter string, making self.filter.remove(idx) panic:

Message:  cannot remove a char from the end of a string
Location: demand-2.0.4/src/select.rs:305

Observed downstream in mise (mise run task picker): type a filter, press Escape, start filtering again, press Backspace → crash.

Fix

Reset cursor_x = 0 alongside filter.clear() when the filter is not saved, so the cursor state stays consistent with the empty filter string.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed selector state not fully resetting when filtering is canceled, ensuring the horizontal cursor returns to its initial position.

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.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 1acdae60-3409-4ce8-9de4-e41dd5b0bffc

📥 Commits

Reviewing files that changed from the base of the PR and between 62f46d5 and 074d713.

📒 Files selected for processing (1)
  • src/select.rs

📝 Walkthrough

Walkthrough

Stopping filtering without saving now resets the selector’s horizontal cursor position to 0, alongside clearing the filter and recomputing pagination.

Changes

Filtering cursor behavior

Layer / File(s) Summary
Reset cursor on unsaved filtering stop
src/select.rs
handle_stop_filtering resets cursor_x when filtering is stopped without saving.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested reviewers: jdx

Poem

Bunny hops, the filter ends,
Cursor homeward swiftly bends.
Clear the text and turn the page,
A tidy state for every stage.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: resetting cursor_x when clearing the filter with Escape.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR preserves the filter cursor invariant when clearing a Select filter.

  • Resets cursor_x to zero when Escape clears an unsaved filter.
  • Prevents a stale cursor position from reaching subsequent filter editing operations.

Confidence Score: 5/5

The 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

Filename Overview
src/select.rs Resets the horizontal filter cursor alongside the filter contents; no issues identified.

Reviews (1): Last reviewed commit: "fix: reset cursor_x when clearing filter..." | Re-trigger Greptile

@jdx
jdx merged commit 87834d6 into jdx:main Jul 28, 2026
9 checks passed
@jdx jdx mentioned this pull request Jul 28, 2026
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