mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1919: Wrong curswant when clicking on empty line or with vsplits
Problem: Wrong curswant when clicking on empty line or with vsplits.
Solution: Don't check for ScreenCols[] before the start of the window
and handle empty line properly.
closes: vim/vim#13132
03cd697d63
This commit is contained in:
parent
f094db0e5c
commit
adb73772d9
@ -1849,56 +1849,55 @@ static void mouse_check_grid(colnr_T *vcolp, int *flagsp)
|
|||||||
int click_grid = mouse_grid;
|
int click_grid = mouse_grid;
|
||||||
int click_row = mouse_row;
|
int click_row = mouse_row;
|
||||||
int click_col = mouse_col;
|
int click_col = mouse_col;
|
||||||
int max_row = Rows;
|
|
||||||
int max_col = Columns;
|
// XXX: this doesn't change click_grid if it is 1, even with multigrid
|
||||||
bool multigrid = ui_has(kUIMultigrid);
|
win_T *wp = mouse_find_win(&click_grid, &click_row, &click_col);
|
||||||
|
// Only use vcols[] after the window was redrawn. Mainly matters
|
||||||
|
// for tests, a user would not click before redrawing.
|
||||||
|
if (wp == NULL || wp->w_redr_type != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ScreenGrid *gp = &wp->w_grid;
|
||||||
|
int start_row = 0;
|
||||||
|
int start_col = 0;
|
||||||
|
grid_adjust(&gp, &start_row, &start_col);
|
||||||
|
if (gp->handle != click_grid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
click_row += start_row;
|
||||||
|
click_col += start_col;
|
||||||
|
|
||||||
colnr_T col_from_screen = -1;
|
colnr_T col_from_screen = -1;
|
||||||
|
|
||||||
win_T *wp = mouse_find_win(&click_grid, &click_row, &click_col);
|
if (gp->chars != NULL
|
||||||
if (wp && multigrid) {
|
&& click_row >= 0 && click_row < gp->rows
|
||||||
max_row = wp->w_grid_alloc.rows;
|
&& click_col >= 0 && click_col < gp->cols) {
|
||||||
max_col = wp->w_grid_alloc.cols;
|
const size_t off = gp->line_offset[click_row] + (size_t)click_col;
|
||||||
}
|
col_from_screen = gp->vcols[off];
|
||||||
|
|
||||||
if (wp && mouse_row >= 0 && mouse_row < max_row
|
if (col_from_screen == MAXCOL) {
|
||||||
&& mouse_col >= 0 && mouse_col < max_col) {
|
// When clicking after end of line, still need to set correct curswant
|
||||||
ScreenGrid *gp = multigrid ? &wp->w_grid_alloc : &default_grid;
|
size_t off_l = gp->line_offset[click_row] + (size_t)start_col;
|
||||||
int use_row = multigrid && mouse_grid == 0 ? click_row : mouse_row;
|
if (gp->vcols[off_l] < MAXCOL) {
|
||||||
int use_col = multigrid && mouse_grid == 0 ? click_col : mouse_col;
|
// Binary search to find last char in line
|
||||||
|
size_t off_r = off;
|
||||||
if (gp->chars != NULL) {
|
while (off_l < off_r) {
|
||||||
const size_t off = gp->line_offset[use_row] + (size_t)use_col;
|
size_t off_m = (off_l + off_r + 1) / 2;
|
||||||
|
if (gp->vcols[off_m] < MAXCOL) {
|
||||||
// Only use vcols[] after the window was redrawn. Mainly matters
|
off_l = off_m;
|
||||||
// for tests, a user would not click before redrawing.
|
} else {
|
||||||
if (wp->w_redr_type == 0) {
|
off_r = off_m - 1;
|
||||||
col_from_screen = gp->vcols[off];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (col_from_screen == MAXCOL) {
|
|
||||||
// When clicking after end of line, still need to set correct curswant
|
|
||||||
size_t off_l = gp->line_offset[use_row];
|
|
||||||
if (gp->vcols[off_l] < MAXCOL) {
|
|
||||||
// Binary search to find last char in line
|
|
||||||
size_t off_r = off;
|
|
||||||
while (off_l < off_r) {
|
|
||||||
size_t off_m = (off_l + off_r + 1) / 2;
|
|
||||||
if (gp->vcols[off_m] < MAXCOL) {
|
|
||||||
off_l = off_m;
|
|
||||||
} else {
|
|
||||||
off_r = off_m - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*vcolp = gp->vcols[off_r] + (int)(off - off_r);
|
|
||||||
} else {
|
|
||||||
// Shouldn't normally happen
|
|
||||||
*vcolp = MAXCOL;
|
|
||||||
}
|
}
|
||||||
} else if (col_from_screen >= 0) {
|
*vcolp = gp->vcols[off_r] + (int)(off - off_r);
|
||||||
// Use the virtual column from vcols[], it is accurate also after
|
} else {
|
||||||
// concealed characters.
|
// Clicking on an empty line
|
||||||
*vcolp = col_from_screen;
|
*vcolp = click_col - start_col;
|
||||||
}
|
}
|
||||||
|
} else if (col_from_screen >= 0) {
|
||||||
|
// Use the virtual column from vcols[], it is accurate also after
|
||||||
|
// concealed characters.
|
||||||
|
*vcolp = col_from_screen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6287,7 +6287,7 @@ describe('float window', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if multigrid then
|
if multigrid then
|
||||||
meths.input_mouse('left', 'press', '', 1, 0, 0)
|
meths.input_mouse('left', 'press', '', 2, 0, 0)
|
||||||
screen:expect{grid=[[
|
screen:expect{grid=[[
|
||||||
## grid 1
|
## grid 1
|
||||||
[2:----------------------------------------]|
|
[2:----------------------------------------]|
|
||||||
@ -6366,7 +6366,7 @@ describe('float window', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if multigrid then
|
if multigrid then
|
||||||
meths.input_mouse('left', 'press', '', 1, 0, 0)
|
meths.input_mouse('left', 'press', '', 2, 0, 0)
|
||||||
screen:expect{grid=[[
|
screen:expect{grid=[[
|
||||||
## grid 1
|
## grid 1
|
||||||
[2:----------------------------------------]|
|
[2:----------------------------------------]|
|
||||||
|
@ -1676,7 +1676,7 @@ describe('ui/mouse/input', function()
|
|||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('getmousepos works correctly', function()
|
it('getmousepos() works correctly', function()
|
||||||
local winwidth = meths.get_option_value('winwidth', {})
|
local winwidth = meths.get_option_value('winwidth', {})
|
||||||
-- Set winwidth=1 so that window sizes don't change.
|
-- Set winwidth=1 so that window sizes don't change.
|
||||||
meths.set_option_value('winwidth', 1, {})
|
meths.set_option_value('winwidth', 1, {})
|
||||||
@ -1771,7 +1771,7 @@ describe('ui/mouse/input', function()
|
|||||||
|
|
||||||
-- Test that mouse position values are properly set for ordinary windows.
|
-- Test that mouse position values are properly set for ordinary windows.
|
||||||
-- Set the float to be unfocusable instead of closing, to additionally test
|
-- Set the float to be unfocusable instead of closing, to additionally test
|
||||||
-- that getmousepos does not consider unfocusable floats. (see discussion
|
-- that getmousepos() does not consider unfocusable floats. (see discussion
|
||||||
-- in PR #14937 for details).
|
-- in PR #14937 for details).
|
||||||
opts.focusable = false
|
opts.focusable = false
|
||||||
meths.win_set_config(float, opts)
|
meths.win_set_config(float, opts)
|
||||||
|
@ -2307,6 +2307,7 @@ describe('ext_multigrid', function()
|
|||||||
{1:~ }|
|
{1:~ }|
|
||||||
]]}
|
]]}
|
||||||
|
|
||||||
|
-- XXX: mouse_check_grid() doesn't work properly when clicking on grid 1
|
||||||
meths.input_mouse('left', 'press', '', 1, 6, 20)
|
meths.input_mouse('left', 'press', '', 1, 6, 20)
|
||||||
-- TODO(bfredl): "batching" input_mouse is formally not supported yet.
|
-- TODO(bfredl): "batching" input_mouse is formally not supported yet.
|
||||||
-- Normally it should work fine in async context when nvim is not blocked,
|
-- Normally it should work fine in async context when nvim is not blocked,
|
||||||
|
@ -4107,6 +4107,39 @@ func Test_normal_click_on_double_width_char()
|
|||||||
let &mouse = save_mouse
|
let &mouse = save_mouse
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_normal_click_on_empty_line()
|
||||||
|
let save_mouse = &mouse
|
||||||
|
set mouse=a
|
||||||
|
botright new
|
||||||
|
call setline(1, ['', '', ''])
|
||||||
|
let row = win_screenpos(0)[0] + 2
|
||||||
|
20vsplit
|
||||||
|
redraw
|
||||||
|
|
||||||
|
call Ntest_setmouse(row, 1)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 1], getcurpos())
|
||||||
|
call Ntest_setmouse(row, 2)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 2], getcurpos())
|
||||||
|
call Ntest_setmouse(row, 10)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 10], getcurpos())
|
||||||
|
|
||||||
|
call Ntest_setmouse(row, 21 + 1)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 1], getcurpos())
|
||||||
|
call Ntest_setmouse(row, 21 + 2)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 2], getcurpos())
|
||||||
|
call Ntest_setmouse(row, 21 + 10)
|
||||||
|
call feedkeys("\<LeftMouse>", 'xt')
|
||||||
|
call assert_equal([0, 3, 1, 0, 10], getcurpos())
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
let &mouse = save_mouse
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_normal33_g_cmd_nonblank()
|
func Test_normal33_g_cmd_nonblank()
|
||||||
" Test that g<End> goes to the last non-blank char and g$ to the last
|
" Test that g<End> goes to the last non-blank char and g$ to the last
|
||||||
" visible column
|
" visible column
|
||||||
|
@ -564,35 +564,38 @@ func Test_virtualedit_mouse()
|
|||||||
let save_mouse = &mouse
|
let save_mouse = &mouse
|
||||||
set mouse=a
|
set mouse=a
|
||||||
set virtualedit=all
|
set virtualedit=all
|
||||||
new
|
botright new
|
||||||
|
let row = win_screenpos(0)[0]
|
||||||
|
20vsplit
|
||||||
|
wincmd p
|
||||||
|
|
||||||
call setline(1, ["text\tword"])
|
call setline(1, ["text\tword"])
|
||||||
redraw
|
redraw
|
||||||
call Ntest_setmouse(1, 4)
|
call Ntest_setmouse(row, 21 + 4)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 4, 0, 4], getcurpos())
|
call assert_equal([0, 1, 4, 0, 4], getcurpos())
|
||||||
call Ntest_setmouse(1, 5)
|
call Ntest_setmouse(row, 21 + 5)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 5, 0, 5], getcurpos())
|
call assert_equal([0, 1, 5, 0, 5], getcurpos())
|
||||||
call Ntest_setmouse(1, 6)
|
call Ntest_setmouse(row, 21 + 6)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 5, 1, 6], getcurpos())
|
call assert_equal([0, 1, 5, 1, 6], getcurpos())
|
||||||
call Ntest_setmouse(1, 7)
|
call Ntest_setmouse(row, 21 + 7)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 5, 2, 7], getcurpos())
|
call assert_equal([0, 1, 5, 2, 7], getcurpos())
|
||||||
call Ntest_setmouse(1, 8)
|
call Ntest_setmouse(row, 21 + 8)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 5, 3, 8], getcurpos())
|
call assert_equal([0, 1, 5, 3, 8], getcurpos())
|
||||||
call Ntest_setmouse(1, 9)
|
call Ntest_setmouse(row, 21 + 9)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 6, 0, 9], getcurpos())
|
call assert_equal([0, 1, 6, 0, 9], getcurpos())
|
||||||
call Ntest_setmouse(1, 12)
|
call Ntest_setmouse(row, 21 + 12)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 9, 0, 12], getcurpos())
|
call assert_equal([0, 1, 9, 0, 12], getcurpos())
|
||||||
call Ntest_setmouse(1, 13)
|
call Ntest_setmouse(row, 21 + 13)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 10, 0, 13], getcurpos())
|
call assert_equal([0, 1, 10, 0, 13], getcurpos())
|
||||||
call Ntest_setmouse(1, 15)
|
call Ntest_setmouse(row, 21 + 15)
|
||||||
call feedkeys("\<LeftMouse>", "xt")
|
call feedkeys("\<LeftMouse>", "xt")
|
||||||
call assert_equal([0, 1, 10, 2, 15], getcurpos())
|
call assert_equal([0, 1, 10, 2, 15], getcurpos())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user