vim icon indicating copy to clipboard operation
vim copied to clipboard

New function to get screenpos of a text character only when it is visible

Open monkoose opened this issue 3 years ago • 6 comments

See comment below.

monkoose avatar Sep 09 '22 08:09 monkoose

Have updated the issue text (because it previously has false statements). Duplicate it here because maillist wan't updated.

There are situation in my vimfu when i really want to know if some position of a window or better character of a buffer is trully visible (not blocking by anything, sign/linenr columns, popup windows). Lets say you want to add popup window to this location or text property only when it is visible etc.

Present screenpos() function has it's limitations: it returns position of the character even if it is blocked by signcolumn when wrap is off and buffer text is shifted to the right, it returns position even when character is blocked by popup windows. Also when wrap is on and last line is wrapped it returns positions of character under @@@ not trully visible line. Also blocked by extends and precedes chars of listchars option of not wrapped lines but which do not fit into the screen.

All this problems are solvable. You can get all required position for popup windows. You can find if listchars has precedes and extends chars and when line doesn't fit to the screen. It is possible to deal with last wrapped invisible chars too. It is harder to get the size of sign/linnr column because there is no dedicated function too, so it requires some hacky implementations. So dealing with all this exceptions is somewhat cumbersome.

Would you find presence of such a function worth the effort to implement?

monkoose avatar Sep 09 '22 08:09 monkoose

I suppose it can be useful, but it might be quite a bit of work to get it right.

brammool avatar Sep 09 '22 18:09 brammool

It is harder to get the size of sign/linnr column because there is no dedicated function too, so it requires some hacky implementations.

It doesn't invalidate the feature request, but you might still be interested in the textoff property of a window:

:echo win_getid()->getwininfo()[0].textoff

See :help getwininfo():

textoff number of columns occupied by any 'foldcolumn', 'signcolumn' and line number in front of the text

lacygoill avatar Sep 12 '22 07:09 lacygoill

It doesn't invalidate the feature request, but you might still be interested in the textoff property of a window

Thank you so much once again @lacygoill How have i overlooked it even if i do use getwininfo() quite often :( Did getwininfo() dict have textoff from time it was added to vim? Or added afterwards?

monkoose avatar Sep 12 '22 07:09 monkoose

It was added in patch 8.2.3627

zeertzjq avatar Sep 12 '22 07:09 zeertzjq

@zeertzjq Thanks.

monkoose avatar Sep 12 '22 07:09 monkoose