-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
popup_create "fixed" option when soft wrapping is on #16231
Comments
I am not sure I follow. Can you please show an example? |
Of course. First recording - Second recording - Both of those are clearly documented in Desired behaviour, that I have implemented in vimscript: Ideally, this would be taken care of by setting |
thanks for clarification. So basically, always move the popup window to the left when Yes I think this change would make sense. A PR would be definitely welcome. |
That was my bad. So move the popup to the left when
Noted. |
I ran into the same issue a few years ago. This is how I solved it basically: vim9script
def OpenPopup()
# " Example text
const text: list<string> =<< trim EOF
0123456789 0123456789 0123456789 0123456789 0123456789
0123456789 0123456789 0123456789
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
EOF
# " If set to a positive value, this will be the popup's maximum width (text will
# " be wrapped); if 0, popup will either have max screen width or max text width
const maxtextwidth = 0
# " Whether to enable popup borders: [above, right, below, left] (must be 0 or 1)
const border: list<number> = [0, 0, 0, 0]
# " Popup padding: [above, right, below, left] (positive numbers)
const padding: list<number> = [0, 1, 0, 1]
# " Maximum text width _in_ the popup window
# " NOTE: strdisplaywidth() uses &tabstop of _current_ window; &tabstop could
# " be different in the popup window. If that's the case, we need a different
# " method to obtain the display width of the text in the popup window
const textwidth: number = maxtextwidth > 0
? maxtextwidth
: text
->len()
->range()
->map((_, i: number): number => strdisplaywidth(text[i]))
->max()
# " Total padding
const pad: number = border[1] + border[3] + padding[1] + padding[3]
# " Popup width (padding and border excluded)
const width: number = textwidth + pad > &columns ? &columns - pad : textwidth
# " Column position for popup window
const screenpos: dict<number> = screenpos(win_getid(), line('.'), col('.'))
const col: number = &columns - screenpos.curscol <= width
? &columns - width - 1
: screenpos.curscol
# " Open popup window at cursor position, shift to left, if popup too wide to
# " fit to the right of the cursor; wrap is always enabled
const popup_id: number = popup_atcursor(text, {
moved: 'any',
col: col,
minwidth: width,
maxwidth: width,
padding: padding,
border: border,
})
enddef
nnoremap gh <ScriptCmd>OpenPopup()<CR> Note that the |
A very brief testing seems to indicate that this works: I've probably broken some tests, so not yet making a pull request. |
Tests are fixed. New tests added. |
Currently,
popup_create()
has an option calledfixed
, which defaults toFALSE
.It basically does what it says on the tin - if there's not enough room, shifts the popup to the left.
However, it stops working if
wrap
is on in the popup window.That's somewhat hostile to plugin maintainers, because occasionally fully shifted popups still have lines that don't fit on the screen (python signatures can get rather nasty).
I have recently implemented in YouCompleteMe a combination of soft-wrapping and popup shifting, all along avoiding vim's ability to shift the popup for me.
The way I have implemented it is such that YouCompleteMe will first shift the popup to the left and then, if there's still not enough space, turn
wrap
on.It would be nice if vim could do this on its own.
The YouCompleteMe pull request, for reference: ycm-core/YouCompleteMe#4252
I wouldn't mind working on this feature, if there are no objections.
The text was updated successfully, but these errors were encountered: