branch: elpa/helm commit f3f6e405c8acf0c2e15101088baa92b7dc96e709 Author: Thierry Volpiatto <thie...@posteo.net> Commit: Thierry Volpiatto <thie...@posteo.net>
Keep focus in helm-window when dropping to dired This is done by advicing temporarily x-dnd-handle-drag-n-drop-event. --- helm-files.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/helm-files.el b/helm-files.el index 8abdf817ab..f5b689a047 100644 --- a/helm-files.el +++ b/helm-files.el @@ -5655,6 +5655,13 @@ and release the mouse in this same buffer.") "Prevent dropping files to helm buffer." (user-error "Can't drop files in helm buffer")) +;; This is used to advice `x-dnd-handle-drag-n-drop-event'. +(defun helm-ff--restore-frame (&rest _args) + (let ((hframe (window-frame (helm-window)))) + (if (eql (selected-frame) hframe) + (select-window (active-minibuffer-window)) + (select-frame hframe)))) + (defun helm-find-files-1 (fname &optional preselect) "Find FNAME filename with PRESELECT filename preselected. @@ -5686,7 +5693,8 @@ Use it for non-interactive calls of `helm-find-files'." (when (fboundp 'dnd-begin-drag-files) (helm-set-local-variable 'helm-drag-mouse-1-fn 'helm-ff-mouse-drag 'dnd-protocol-alist - (append helm-dnd-protocol-alist dnd-protocol-alist))) + (append helm-dnd-protocol-alist dnd-protocol-alist)) + (advice-add 'x-dnd-handle-drag-n-drop-event :after #'helm-ff--restore-frame)) (unless helm-source-find-files (setq helm-source-find-files (helm-make-source "Find Files" 'helm-source-ffiles))) @@ -5719,7 +5727,8 @@ Use it for non-interactive calls of `helm-find-files'." :prompt "Find files or url: " :buffer "*helm find files*") (helm-ff--update-resume-after-hook nil t) - (setq helm-ff-default-directory nil)))) + (setq helm-ff-default-directory nil) + (advice-remove 'x-dnd-handle-drag-n-drop-event 'helm-ff--restore-frame)))) (defvar helm-find-files-dummy-source (helm-build-dummy-source "New file or directory"