tumashu / ivy-posframe

ivy-posframe is a ivy extension, which let ivy use posframe to show its candidate menu, ivy-posframe is a **GNU ELPA** package.
414 stars 26 forks source link

ivy-posframe disappear in a flash after ivy-posframe-avy #114

Closed allenryb closed 3 years ago

allenryb commented 3 years ago

When I use ivy-posframe-avy (pressing C-') in M-x, the avy feature works but disappears in a flash. That is, the avy-keys asdfg... appears at the left of candidates but the ivy-posframe frame will disappear in a second.

Another problem is for ivy-posframe-swiper-avy. It shows the avy-keys in the normal buffer frame, not in the ivy-posframe frame.

allenryb commented 3 years ago

This may be realted with https://github.com/tumashu/ivy-posframe/issues/21

If I load the following code by @kongds, then ivy-posframe-avy works fine.

(defvar ivy-posframe--first-show t)
(defun ivy-posframe-cleanup ()
  "Cleanup ivy's posframe."
  (setq ivy-posframe--first-show t)
  (when (posframe-workable-p)
    (posframe-hide ivy-posframe-buffer)))
(defun ivy-posframe--display (str &optional poshandler)
  "Show STR in ivy's posframe with POSHANDLER."
  (if (not (posframe-workable-p))
      (ivy-display-function-fallback str)
    (with-ivy-window
      (if (not ivy-posframe--first-show)
          (with-current-buffer ivy-posframe-buffer
            (erase-buffer)
            (insert str))
          (setq ivy-posframe--first-show nil)
          (apply #'posframe-show
                 ivy-posframe-buffer
                 :font ivy-posframe-font
                 :string str
                 :position (point)
                 :poshandler poshandler
                 :background-color (face-attribute 'ivy-posframe :background nil t)
                 :foreground-color (face-attribute 'ivy-posframe :foreground nil t)
                 :internal-border-width ivy-posframe-border-width
                 :internal-border-color (face-attribute 'ivy-posframe-border :background nil t)
                 :override-parameters ivy-posframe-parameters
                 (funcall ivy-posframe-size-function)))
      (ivy-posframe--add-prompt 'ignore)))
  (with-current-buffer ivy-posframe-buffer
    (setq-local truncate-lines ivy-truncate-lines)))
allenryb commented 3 years ago

By comparing with the original code of ivy-posframe--display and the above, the :hidehandler #'ivy-posframe-hidehandler with ivy-posframe-avy may cause this problem.

The buffers may change at the step with-selected-window (ivy-posframe--window). I use the following code to check the buffers at this step.

(defun ivy-posframe-avy ()
  "Ivy-posframe's `ivy-avy'."
  (interactive)
  (let ((avy-pre-action #'ignore))
    (message "buffer-name-outside is %s" (buffer-name))    ;; Line 1
    (with-selected-window (ivy-posframe--window)
      (message "buffer-name-inside is %s" (buffer-name))   ;; Line 2
      (ivy-avy))))

And the message results are

buffer-name-outside is  *Minibuf-1*                        ;; Line 1
buffer-name-inside is  *ivy-posframe-buffer*               ;; Line 2

which give the different returns of ivy-posframe-hidehandler.

tumashu commented 3 years ago

Should be fixed, please test again

allenryb commented 3 years ago

The problem has been fixed. Thanks!