branch: master commit e41cbec13c4ede6785555d45db44efd0d1f47fa2 Author: Muir Manders <m...@mnd.rs> Commit: Oleh Krehel <ohwoeo...@gmail.com>
ivy.el (ivy-immediate-done): Fix parent dirs for read-directory-name When selecting a directory, if you removed elements from the default directory (e.g. by pressing DEL) and then used ivy-immediate-done, you were getting back the starting directory instead of the ancestor directory. Fixes #2165 Fixes #2198 --- ivy-test.el | 8 +++++++- ivy.el | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ivy-test.el b/ivy-test.el index a6fb301..e4ce500 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -950,7 +950,13 @@ will bring the behavior in line with the newer Emacsen." (ivy-with '(read-directory-name "cd: ") "tmp C-j C-M-j" - :dir "/")))) + :dir "/"))) + (should + (equal "/" + (ivy-with + '(read-directory-name "cd: ") + "DEL C-M-j" + :dir "/tmp")))) (ert-deftest ivy-partial-files () (when (file-exists-p "/tmp/ivy-partial-test") diff --git a/ivy.el b/ivy.el index 983b87a..7fb4e9d 100644 --- a/ivy.el +++ b/ivy.el @@ -1164,8 +1164,10 @@ If the text hasn't changed as a result, forward to `ivy-alt-done'." (eq (ivy-state-collection ivy-last) #'read-file-name-internal)) (if (ivy-state-def ivy-last) - (if (> (length ivy--directory) - (1+ (length (expand-file-name (ivy-state-def ivy-last))))) + (if (and + (file-exists-p (ivy-state-def ivy-last)) + (/= (length ivy--directory) + (1+ (length (expand-file-name (ivy-state-def ivy-last)))))) ivy--directory (copy-sequence (ivy-state-def ivy-last))) ivy--directory))