branch: master
commit 5424a5643ee723102a7a1b3f7f434cc83cf735dc
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy--handle-directory): Extract
* ivy-test.el (ivy--handle-directory): Add test.
---
ivy-test.el | 6 ++++++
ivy.el | 14 +++++++++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index e4ce500..6ed6484 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1384,6 +1384,12 @@ a buffer visiting a file."
(ivy--yank-handle-case-fold "irstName"))
"irstname")))
+(ert-deftest ivy--handle-directory ()
+ (should (string= (ivy--handle-directory "/") "/"))
+ (should (string= (let ((ivy--directory "/tmp/"))
+ (ivy--handle-directory "/sudo::"))
+ "/sudo::/tmp/")))
+
(provide 'ivy-test)
;;; ivy-test.el ends here
diff --git a/ivy.el b/ivy.el
index 1b9090b..1588efc 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1010,14 +1010,18 @@ contains a single candidate.")
(ivy--cd dir)
(ivy--exhibit))))
+(defun ivy--handle-directory (input)
+ "Detect the next directory based on special values of INPUT."
+ (cond ((string= input "/")
+ "/")
+ ((string= input "/sudo::")
+ (concat input ivy--directory))))
+
(defun ivy--directory-done ()
"Handle exit from the minibuffer when completing file names."
- (let (dir)
+ (let ((dir (ivy--handle-directory ivy-text)))
(cond
- ((equal ivy-text "/")
- (ivy--cd "/"))
- ((equal ivy-text "/sudo::")
- (setq dir (concat ivy-text (expand-file-name ivy--directory)))
+ (dir
(let ((inhibit-message t))
(ivy--cd dir)))
((ivy--directory-enter))