Fuco1 / dired-hacks

Collection of useful dired additions
GNU General Public License v3.0
873 stars 77 forks source link

dired-narrow moves the cursor unnecessarily in dired buffer #188

Open geza-herman opened 2 years ago

geza-herman commented 2 years ago

If adding a new character at the filter prompt creates a string, which matches both the current and the next line in the dired buffer, the cursor will move down in the dired buffer.

Repro: create an empty directory, and put files there named aaaaaaa1, aaaaaaa2, aaaaaaa3, aaaaaaa4. Now, start dired in this directory, run dired-narrow, and type the string aaaaaaa at the Filter: prompt. Notice, that each press of a will move the cursor down in the dired buffer. If the cursor reaches the bottom, it will move upwards once, and then move downwards again. I expect that the cursor doesn't move if the currently selected dired entry still matches the filter.

I tried to fix this, and it seems to work if I add a condition at the bottom of dired-narrow--update (checks whether the cursor stands on an invisible line), but I'm not sure that this is a proper fix:

    (when (or (get-text-property (point) 'invisible) (not (dired-utils-is-file-p)))
      (unless (dired-hacks-next-file)
        (dired-hacks-previous-file))
      (unless (dired-utils-get-filename)
        (dired-hacks-previous-file)))