Macvim: Wrong cursor placement and selection when using mouse

Created on 17 Dec 2019  路  5Comments  路  Source: macvim-dev/macvim

Describe the bug
Clicking with the mouse beyond the end of a line not always put the cursor at the last character. When selecting a whole line with the mouse, the selection stops at the same position as when clicking beyond the end of the line.

To Reproduce
Detailed steps to reproduce the behavior:

  1. Run mvim -u NONE -U NONE -c ':help ls'
  2. Click beyond the line starting with "Each buffer has a unique number."
  3. The cursor gets placed at the first "l" of "will"
  4. Select the whole line from the left to the right with the mouse. The selection stops at the same position, at the first "l" of "will".

Expected behavior
The cursor gets placed at the last character an the selection covers the whole line.

Screenshots
screenshot for 3. (the red arrow shows the position I've clicked):
Screenshot 2019-12-17 at 09 44 46

screenshot for 4.:
Screenshot 2019-12-17 at 09 46 35

Environment (please complete the following information):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 18 2019 19:04:21)
macOS version
Included patches: 1-2318
Compiled by [email protected]
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tcl
+arabic            +find_in_path      +mouse_xterm       +termguicolors
+autocmd           +float             +multi_byte        +terminal
+autochdir         +folding           +multi_lang        +terminfo
-autoservername    -footer            -mzscheme          +termresponse
+balloon_eval      +fork()            -netbeans_intg     +textobjects
+balloon_eval_term +fullscreen        +num64             +textprop
+browse            -gettext           +odbeditor         +timers
++builtin_terms    -hangul_input      +packages          +title
+byte_offset       +iconv             +path_extra        +toolbar
+channel           +insert_expand     -perl              +transparency
+cindent           +job               +persistent_undo   +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
-cscope            +localmap          -ruby              +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con_gui    +mksession         +smartindent       -X11
+diff              +modify_fname      -sound             -xfontset
+digraphs          +mouse             +spell             +xim
+dnd               +mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        -mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary
+extra_search      +mouse_sgr         -tag_old_static
-farsi             -mouse_sysmouse    -tag_any_white
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno
-unknown-pragmas -pipe  -DMACOS_X -DMACOS_X_DARWIN  -Os -fno-caret-diagnostics
 -fno-color-diagnostics -fno-diagnostics-fixit-info -pipe -pedantic -Weverythi
ng -Wunused-macros -Wno-padded -Wno-format-nonliteral -Wno-switch-enum -Wno-co
vered-switch-default -Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-reserved-
id-macro -Wno-disabled-macro-expansion -Wno-documentation-unknown-command -Wno
-documentation-deprecated-sync -Wsign-compare -U_FORTIFY_SOURCE -D_FORTIFY_SOU
RCE=1
Linking: clang    -o Vim -framework Cocoa -framework Carbon       -lm -lncurse
s  -liconv -framework AppKit

Most helpful comment

This should be fixed by the latest merge.

All 5 comments

Yes, I get the same bug.

I confirm it, but this should be tested also on GVim and previous versions to make sure where this bug was introduced.

Huh, this doesn't happen on 8.1.2234 (the version with a released binary). I will need to take a look. Also, given Vim 8.2 is officially out I need to merge and see if it's fixed.

It seems to be that the following chunk from patch 8.1.2304 causes this issue:

*** ../vim-8.1.2303/src/mouse.c 2019-11-13 22:35:15.759521804 +0100
--- src/mouse.c 2019-11-16 18:12:11.385526875 +0100

*** 2881,2886 ****
--- 2882,2892 ----
        col += row * (win->w_width - off);
        // add skip column (for long wrapping line)
        col += win->w_skipcol;
+       // limit to text length plus one
+       p = ml_get_buf(win->w_buffer, lnum, FALSE);
+       count = STRLEN(p);
+       if (col > count)
+           col = count;
      }

      if (!win->w_p_wrap)
***************

In 8.2 that chunk is gone (patch 8.1.2321 moves it to another function) so I expect that going to Vim 8.2 will fix this issue.

This should be fixed by the latest merge.

Was this page helpful?
0 / 5 - 0 ratings