tumashu / vertico-posframe

GNU General Public License v3.0
119 stars 16 forks source link

Long paths #37

Open goldfita opened 1 year ago

goldfita commented 1 year ago

When the path length exceeds the posframe length, the files get cut off.

posframe_cursor_end_path

I'm unable to use the left/right arrow keys, but I can backup with M-b. Then it looks like this.

posframe_cursor_in_path

Also, I noticed a couple other quirks. When the path is too long, the posframe width changes. Also, when you shrink the emacs frame, hit tab, then maximize, the posframe gets moved. You can hit tab again to recenter.

posframe_not_centered

cxa commented 7 months ago

You can use my workaround:

(advice-add 'vertico-posframe--show
            :before
            (defun vertico-posframe--show/before (&rest _args)
              ;; https://github.com/minad/vertico/blob/0f12d85a5a38353471d7657572e69f00fa1b9639/vertico.el#L611
              (setq vertico-posframe-truncate-lines
                    (< (point) (* 0.8 (window-width (active-minibuffer-window)))))))
YueRen commented 1 month ago

What issue is the workaround supposed to fix? It didn't fix the following problem for me:

  1. Do C-x C-f to be prompted to find file
  2. Write an filename so long that the path exceeds the width of the posframe and notice the width of the posframe increasing.
  3. Do C-g to abort find file
  4. Do another C-x C-f and notice that the posframe is glitched out.

(Note: You can replace C-x C-f with anything that invokes a posframe, for example M-x)

lucius-martius commented 1 month ago

@YueRen I use this workaround instead:

(defun vertico-posframe-set-auto-hscroll-current-line ()
  (when (bound-and-true-p vertico--input)
    (let ((inhibit-message t))
      (setq-local auto-hscroll-mode 'current-line))))
(add-hook 'minibuffer-setup-hook 'vertico-posframe-set-auto-hscroll-current-line)

You may need to make it more complex if you use things like vertico-multiform, since this affects all vertico minibuffers, not just vertico-posframe ones.

YueRen commented 1 month ago

@lucius-martius Thanks for the snippet! But I can't detect any change of behaviour, what is it supposed to affect?

lucius-martius commented 1 month ago

@YueRen It's supposed to enable the vertical scrolling only for the long line (i.e. auto-hscroll-mode), leaving the other lines scrolled to the beginning of the line.

In a vertico buffer with vertico-posframe this means that when you enter a long path at the top it should only shift the prompt line to the right, not the result lines. @cxa's solution on the other hand is supposed to break the line before it would scroll the whole buffer right, but that never worked for me.

My snippet might not work immediately, since a vertico buffer might already exist. You might need to either kill the vertico buffer or restart emacs with the snippet in your config.

If it still doesn't work, I have no idea. Maybe bisect your Vertico(-posframe) config or other packages that affect it. It definitely works for me. I can easily reproduce the issue with my snippet commented out and it's completely fixed when I enable it again.

YueRen commented 1 month ago

@lucius-martius Nvm, I think I was confusing two different issues. That code works for me as well, thanks a lot for sharing!

tumashu commented 1 month ago

Please try and test this commit: https://github.com/tumashu/vertico-posframe/commit/17a21feb1f7ca415665e18360f89e995d3a2c4bd

YueRen commented 1 month ago

@tumashu works for me out of the box, thanks!!!

tumashu commented 1 month ago

OK, I will see other's feedback, if no problem, i will merge it.

Long path #49