[vim/vim] getmousepos().column returns "the length of the text in bytes" plus one (#8474)

13 views
Skip to first unread message

Daniel Steinberg

unread,
Jun 28, 2021, 11:25:32 AM6/28/21
to vim/vim, Subscribed

Describe the bug

getmousepos().column returns "the length of the text in bytes" plus one

To Reproduce

  1. Run vim --clean (or gvim --clean, etc.)
  2. Insert text "hello"
  3. Click on the line of text, to the right of "hello"
  4. :echo getmousepos().column
  5. Output of 6

Expected behavior

Output of 5, since :help getmousepos() says "When the position is after the text then 'column' is the length of the text in bytes" and the length of "hello" is 5 bytes.

Environment (please complete the following information):

  • Vim version: 8.2.3070
  • OS: Ubuntu 21.04
  • Terminal: Konsole 20.12.3


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Jun 28, 2021, 3:16:18 PM6/28/21
to vim/vim, Subscribed

This is a mistake in the help text. Clicking after the last character returns one more. Otherwise you would not be able to tell the difference between clicking on the last character. I'll update the help.

Bram Moolenaar

unread,
Jun 28, 2021, 3:16:18 PM6/28/21
to vim/vim, Subscribed

Closed #8474.

Daniel Steinberg

unread,
Jun 28, 2021, 3:24:21 PM6/28/21
to vim/vim, Subscribed

Thanks!

I see that similar behavior is not present for getmousepos().line. For example, if I click below the h in the hello example from above, getmousepos returns 1 for the line. Is that the intended/desired behavior?

Bram Moolenaar

unread,
Jun 28, 2021, 4:12:34 PM6/28/21
to vim/vim, Subscribed


> I see that similar behavior is not present for `getmousepos().line`.

> For example, if I click below the `h` in the `hello` example from
> above, `getmousepos` returns `1` for the line. Is that the
> intended/desired behavior?

Well, there really isn't a line below the last one. Trying to navigate
there would result in an error. While navigating to the last column
plus one usually works.

You can use screenrow, but it's not related to the buffer text.

I rather not change how this works, it might break a plugin.

--
hundred-and-one symptoms of being an internet addict:
46. Your wife makes a new rule: "The computer cannot come to bed."

/// 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 ///
Reply all
Reply to author
Forward
0 new messages