branch: master commit e58231e7446bc7a1623ad92190080a4180a07f50 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
ivy.el (ivy-immediate-done): Fix for when "C-j" changed cwd * ivy-test.el (ivy-read-directory-name): Add test. Fixes #2165 --- ivy-test.el | 8 +++++++- ivy.el | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ivy-test.el b/ivy-test.el index 10bf189..2a9931b 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -940,7 +940,13 @@ will bring the behavior in line with the newer Emacsen." (ivy-with '(read-directory-name "cd: ") "C-M-j" - :dir "/tmp")))) + :dir "/tmp"))) + (should + (equal "/tmp/" + (ivy-with + '(read-directory-name "cd: ") + "tmp C-j C-M-j" + :dir "/")))) (ert-deftest ivy-partial-files () (when (file-exists-p "/tmp/ivy-partial-test") diff --git a/ivy.el b/ivy.el index c24bcd7..06fde10 100644 --- a/ivy.el +++ b/ivy.el @@ -1125,8 +1125,12 @@ If the text hasn't changed as a result, forward to `ivy-alt-done'." ((and (string= ivy-text "") (eq (ivy-state-collection ivy-last) #'read-file-name-internal)) - (or (copy-sequence (ivy-state-def ivy-last)) - ivy--directory)) + (if (ivy-state-def ivy-last) + (if (> (length ivy--directory) + (1+ (length (expand-file-name (ivy-state-def ivy-last))))) + ivy--directory + (copy-sequence (ivy-state-def ivy-last))) + ivy--directory)) (t (expand-file-name ivy-text ivy--directory)))) (insert (ivy-state-current ivy-last))