Cursor positioning is not correct with virtual text

17 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Jul 27, 2022, 12:02:32 PM7/27/22
to vim_dev
Hi,

After executing the following set of commands:

----------------------------------------------------------
new
call setline(1, ["A quick brown fox jumps over the fence"])
call prop_type_add("MyProp", #{bufnr: bufnr(), highlight: 'Search'})
call prop_add(1, 9, #{type: "MyProp", text: "Hello World", length: 4})
call cursor(1, 15)
----------------------------------------------------------

I expected the cursor to be positioned at column 15. But the cursor
is positioned at column 26. If you press CTRL-L, then the
cursor is moved to a different column.

- Yegappan

Yegappan Lakshmanan

unread,
Jul 27, 2022, 1:32:39 PM7/27/22
to vim_dev
I also noticed other problems with virtual text. For example, with the above
script, if you place the cursor at the beginning of the line and execute veey,
then it copies the text "A quick brown fox jumps".

- Yegappan

Bram Moolenaar

unread,
Jul 27, 2022, 5:21:47 PM7/27/22
to vim...@googlegroups.com, Yegappan Lakshmanan
I already mentioned that the current code only has the first step, there
is lots more to do to get it right. This is complicated, many parts of
the code depend on the relation between buffer text and the actually
displayed text.

Nevertheless, the idea of using text properties, defining the position,
how it shifts with the text, highlighting, and how the text is defined,
already give you an idea of how the virtual text can be added. Main
thing missing is how to position text after the end of the line. We
probably also want right-aligned somehow (and figure out what to do when
it doesn't fit, might need some alternatives).

And it shows how it differs from concealing, which depends on syntax
highlighting, which can't always be figured out within the line itself,
making it too slow to use in general (which is why wrapping is based on
the text without concealing).

--
hundred-and-one symptoms of being an internet addict:
162. You go outside and look for a brightness knob to turn down the sun.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Aug 2, 2022, 10:53:36 AM8/2/22
to vim...@googlegroups.com, Yegappan Lakshmanan
Checked this now: It looks correct to me. The cursor is positioned in
text column 15, which is shifted to the right by the virtual text, thus
that makes it end up in screen column 26, since the text is 11 cells
wide. CTRL-L does not change this (probably fixed recently).

--
hundred-and-one symptoms of being an internet addict:
231. You sprinkle Carpet Fresh on the rugs and put your vacuum cleaner
in the front doorway permanently so it always looks like you are
actually attempting to do something about that mess that has amassed
since you discovered the Internet.

Yegappan Lakshmanan

unread,
Aug 2, 2022, 11:09:58 AM8/2/22
to Bram Moolenaar, vim_dev
Hi Bram,

On Tue, Aug 2, 2022 at 7:53 AM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Yegappan wrote:
>
> > After executing the following set of commands:
> >
> > ----------------------------------------------------------
> > new
> > call setline(1, ["A quick brown fox jumps over the fence"])
> > call prop_type_add("MyProp", #{bufnr: bufnr(), highlight: 'Search'})
> > call prop_add(1, 9, #{type: "MyProp", text: "Hello World", length: 4})
> > call cursor(1, 15)
> > ----------------------------------------------------------
> >
> > I expected the cursor to be positioned at column 15. But the cursor
> > is positioned at column 26. If you press CTRL-L, then the
> > cursor is moved to a different column.
>
> Checked this now: It looks correct to me. The cursor is positioned in
> text column 15, which is shifted to the right by the virtual text, thus
> that makes it end up in screen column 26, since the text is 11 cells
> wide. CTRL-L does not change this (probably fixed recently).
>

Yes. The recent patches fixed this problem.

Thanks,
Yegappan
Reply all
Reply to author
Forward
0 new messages