win_line_start(wp, &wlv, FALSE);
- char_u *prev_ptr = ptr;
// Repeat for the whole displayed line.
for (;;)
{
}
#endif
+#ifdef FEAT_SEARCH_EXTRA
if (wlv.n_extra == 0)
{
-#ifdef FEAT_SEARCH_EXTRA
// Check for start/end of 'hlsearch' and other matches.
// After end, check for start/end of next match.
// When another match, have to check for start again.
// and bad things happen.
if (*ptr == NUL)
has_match_conc = 0;
-#endif
-
- prev_ptr = ptr;
}
+#endif
#ifdef FEAT_DIFF
if (wlv.diff_hlf != (hlf_T)0)
// have made it invalid.
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + v;
- prev_ptr = ptr;
# ifdef FEAT_CONCEAL
// no concealing past the end of the line, it interferes
// with line highlighting
#ifdef FEAT_LINEBREAK
int c0;
#endif
- prev_ptr = ptr;
+#ifdef FEAT_SPELL
+ char_u *prev_ptr = ptr;
+#endif
// Get a character from the line itself.
c = *ptr;
else
ScreenAttrs[wlv.off] = wlv.char_attr;
- ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
+ ScreenCols[wlv.off] = wlv.vcol;
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
{
if (wlv.tocol == wlv.vcol)
++wlv.tocol;
- ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
+ ScreenCols[wlv.off] = wlv.vcol;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
* The characters that are currently on the screen are kept in ScreenLines[].
* It is a single block of characters, the size of the screen plus one line.
* The attributes for those characters are kept in ScreenAttrs[].
- * The byte offset in the line is kept in ScreenCols[].
+ * The virtual column in the line is kept in ScreenCols[].
*
* "LineOffset[n]" is the offset from ScreenLines[] for the start of line 'n'.
* The same value is used for ScreenLinesUC[], ScreenAttrs[] and ScreenCols[].
// Only use ScreenCols[] after the window was redrawn. Mainly matters
// for tests, a user would not click before redrawing.
// Do not use when 'virtualedit' is active.
- if (curwin->w_redr_type <= UPD_VALID_NO_UPDATE && !virtual_active())
+ if (curwin->w_redr_type <= UPD_VALID_NO_UPDATE)
col_from_screen = ScreenCols[off];
#ifdef FEAT_FOLDING
// Remember the character under the mouse, it might be a '-' or '+' in
redraw_cmdline = TRUE; // show visual mode later
}
- if (col_from_screen >= 0)
+ if (col_from_screen == MAXCOL)
{
- // Use the column from ScreenCols[], it is accurate also after
- // concealed characters.
- curwin->w_cursor.col = col_from_screen;
- if (col_from_screen == MAXCOL)
+ // When clicking after end of line, still need to set correct curswant
+ int off_l = LineOffset[prev_row];
+ if (ScreenCols[off_l] < MAXCOL)
{
- curwin->w_curswant = col_from_screen;
- curwin->w_set_curswant = FALSE; // May still have been TRUE
- mouse_past_eol = TRUE;
- if (inclusive != NULL)
- *inclusive = TRUE;
+ // Binary search to find last char in line
+ int off_r = off_l + prev_col;
+ int off_click = off_r;
+ while (off_l < off_r)
+ {
+ int off_m = (off_l + off_r + 1) / 2;
+ if (ScreenCols[off_m] < MAXCOL)
+ off_l = off_m;
+ else
+ off_r = off_m - 1;
+ }
+ col = ScreenCols[off_r] + (off_click - off_r);
}
else
- {
- curwin->w_set_curswant = TRUE;
- if (inclusive != NULL)
- *inclusive = FALSE;
- }
- check_cursor_col();
+ // Shouldn't normally happen
+ col = MAXCOL;
}
- else
+ else if (col_from_screen >= 0)
{
- curwin->w_curswant = col;
- curwin->w_set_curswant = FALSE; // May still have been TRUE
- if (coladvance(col) == FAIL) // Mouse click beyond end of line
- {
- if (inclusive != NULL)
- *inclusive = TRUE;
- mouse_past_eol = TRUE;
- }
- else if (inclusive != NULL)
- *inclusive = FALSE;
+ // Use the virtual column from ScreenCols[], it is accurate also after
+ // concealed characters.
+ col = col_from_screen;
+ }
+
+ curwin->w_curswant = col;
+ curwin->w_set_curswant = FALSE; // May still have been TRUE
+ if (coladvance(col) == FAIL) // Mouse click beyond end of line
+ {
+ if (inclusive != NULL)
+ *inclusive = TRUE;
+ mouse_past_eol = TRUE;
}
+ else if (inclusive != NULL)
+ *inclusive = FALSE;
count = IN_BUFFER;
if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum
call test_setmouse(1, 16)
call feedkeys("\<LeftMouse>", "tx")
call assert_equal([0, 1, 20, 0, 20], getcurpos())
+ " click on 'e' of "here" puts cursor there
+ call test_setmouse(1, 19)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 23], getcurpos())
+ " click after end of line puts cursor on 'e' without 'virtualedit'
+ call test_setmouse(1, 20)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 24], getcurpos())
+ call test_setmouse(1, 21)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 25], getcurpos())
+ call test_setmouse(1, 22)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 26], getcurpos())
+ call test_setmouse(1, 31)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 35], getcurpos())
+ call test_setmouse(1, 32)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 36], getcurpos())
+
+ set virtualedit=all
+ " click on 'h' of "here" puts cursor there
+ call test_setmouse(1, 16)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 20, 0, 20], getcurpos())
+ " click on 'e' of "here" puts cursor there
+ call test_setmouse(1, 19)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 23, 0, 23], getcurpos())
+ " click after end of line puts cursor there without 'virtualedit'
+ call test_setmouse(1, 20)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 24, 0, 24], getcurpos())
+ call test_setmouse(1, 21)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 24, 1, 25], getcurpos())
+ call test_setmouse(1, 22)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 24, 2, 26], getcurpos())
+ call test_setmouse(1, 31)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 24, 11, 35], getcurpos())
+ call test_setmouse(1, 32)
+ call feedkeys("\<LeftMouse>", "tx")
+ call assert_equal([0, 1, 24, 12, 36], getcurpos())
bwipe!
- set mouse&
+ set mouse& virtualedit&
endfunc
" vim: shiftwidth=2 sts=2 expandtab
call assert_equal([0, 1, 1, 0, 1], getcurpos())
call test_setmouse(1, 2)
call feedkeys("\<LeftMouse>", 'xt')
- call assert_equal([0, 1, 2, 0, 8], getcurpos())
+ call assert_equal([0, 1, 2, 0, 2], getcurpos())
call test_setmouse(1, 3)
call feedkeys("\<LeftMouse>", 'xt')
- call assert_equal([0, 1, 2, 0, 8], getcurpos())
+ call assert_equal([0, 1, 2, 0, 3], getcurpos())
call test_setmouse(1, 7)
call feedkeys("\<LeftMouse>", 'xt')
- call assert_equal([0, 1, 2, 0, 8], getcurpos())
+ call assert_equal([0, 1, 2, 0, 7], getcurpos())
call test_setmouse(1, 8)
call feedkeys("\<LeftMouse>", 'xt')
call assert_equal([0, 1, 2, 0, 8], getcurpos())
call assert_equal([0, 1, 4, 0, 10], getcurpos())
call test_setmouse(1, 11)
call feedkeys("\<LeftMouse>", 'xt')
- call assert_equal([0, 1, 4, 0, 10], getcurpos())
+ call assert_equal([0, 1, 4, 0, 11], getcurpos())
call test_setmouse(1, 12)
call feedkeys("\<LeftMouse>", 'xt')
call assert_equal([0, 1, 5, 0, 12], getcurpos())
call test_setmouse(1, 13)
call feedkeys("\<LeftMouse>", 'xt')
- call assert_equal([0, 1, 5, 0, v:maxcol], getcurpos())
+ call assert_equal([0, 1, 5, 0, 13], getcurpos())
bwipe!
let &mouse = save_mouse
call test_setmouse(1, 9)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 6, 0, 9], getcurpos())
+ call test_setmouse(1, 12)
+ call feedkeys("\<LeftMouse>", "xt")
+ call assert_equal([0, 1, 9, 0, 12], getcurpos())
+ call test_setmouse(1, 13)
+ call feedkeys("\<LeftMouse>", "xt")
+ call assert_equal([0, 1, 10, 0, 13], getcurpos())
call test_setmouse(1, 15)
call feedkeys("\<LeftMouse>", "xt")
call assert_equal([0, 1, 10, 2, 15], getcurpos())
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1725,
/**/
1724,
/**/