Skip to content

Selection of first match after changes to the input doesn't always work #253

@tsdh

Description

@tsdh

After 126158d, the first match should be selected after the input has changed with the exception of swiper. It works in the case I constructed in #231 but not always. Here's a test case which currently fails:

(should (equal
         (ivy-with '(ivy-read "pattern: " '("aba"
                        "baa"
                        "abc"))
                   "a b <down> <backspace> C-m")
         "aba")) ;; What's actually selected now is baa

Here I'd expect the first item "aba" to be selected because the first matching element should be selected after changes to the input. What's actually selected is "baa" which is neither the first match nor the last match so completely implausible. So that's a bug but I also have two other points.

  1. I agree with @PythonNut's comment in Ivy: default input should not stick after typing #231 in that one might want to customize that behavior on a per-command basis. Right now swiper and counsel-git-grep are exceptions identified by the last state having the unwind function swiper--cleanup, but testing for some specific unwind function seems to be the wrong thing to do. So I suggest to introduce some defcustom ivy-select-first-after-change-list (I'm not convinced of the name) and then changing the test to (memq this-command ivy-select-first-after-change-list).
  2. I think that once a user switched candidates explicitly with C-n/C-p/<up>/<down>, the selection of the first candidate after changes should be disabled, i.e., the selection should stick to the last one in case it is still valid. If that were implemented, the test case above should expect "abc" instead of "aba".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions