mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:8.2.3193: screenpos() is wrong when 'display' is "lastline"
Problem: screenpos() is wrong when the last line is partially visible and
'display' is "lastline".
Solution: Also compute the position for a partially visible line.
(closes vim/vim#8599)
189663bdac
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
f3bf1fbf60
commit
11d2704274
@ -921,7 +921,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
||||
colnr_T coloff = 0;
|
||||
bool visible_row = false;
|
||||
|
||||
if (pos->lnum >= wp->w_topline && pos->lnum < wp->w_botline) {
|
||||
if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline) {
|
||||
row = plines_m_win(wp, wp->w_topline, pos->lnum - 1) + 1;
|
||||
visible_row = true;
|
||||
} else if (pos->lnum < wp->w_topline) {
|
||||
@ -955,15 +955,15 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
||||
|
||||
col -= wp->w_leftcol;
|
||||
|
||||
if (col >= 0 && col < wp->w_width) {
|
||||
if (col >= 0 && col < wp->w_width && row + rowoff <= wp->w_height) {
|
||||
coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1;
|
||||
} else {
|
||||
// character is left, right or below of the window
|
||||
scol = ccol = ecol = 0;
|
||||
// character is left or right of the window
|
||||
if (local) {
|
||||
coloff = col < 0 ? -1 : wp->w_width_inner + 1;
|
||||
} else {
|
||||
row = 0;
|
||||
row = rowoff = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,25 +82,41 @@ func Test_screenpos()
|
||||
let winid = win_getid()
|
||||
let [winrow, wincol] = win_screenpos(winid)
|
||||
call assert_equal({'row': winrow,
|
||||
\ 'col': wincol + 0,
|
||||
\ 'curscol': wincol + 7,
|
||||
\ 'endcol': wincol + 7}, winid->screenpos(1, 1))
|
||||
\ 'col': wincol + 0,
|
||||
\ 'curscol': wincol + 7,
|
||||
\ 'endcol': wincol + 7}, winid->screenpos(1, 1))
|
||||
call assert_equal({'row': winrow,
|
||||
\ 'col': wincol + 13,
|
||||
\ 'curscol': wincol + 13,
|
||||
\ 'endcol': wincol + 13}, winid->screenpos(1, 7))
|
||||
\ 'col': wincol + 13,
|
||||
\ 'curscol': wincol + 13,
|
||||
\ 'endcol': wincol + 13}, winid->screenpos(1, 7))
|
||||
call assert_equal({'row': winrow + 2,
|
||||
\ 'col': wincol + 1,
|
||||
\ 'curscol': wincol + 1,
|
||||
\ 'endcol': wincol + 1}, screenpos(winid, 2, 22))
|
||||
\ 'col': wincol + 1,
|
||||
\ 'curscol': wincol + 1,
|
||||
\ 'endcol': wincol + 1}, screenpos(winid, 2, 22))
|
||||
setlocal number
|
||||
call assert_equal({'row': winrow + 3,
|
||||
\ 'col': wincol + 9,
|
||||
\ 'curscol': wincol + 9,
|
||||
\ 'endcol': wincol + 9}, screenpos(winid, 2, 22))
|
||||
\ 'col': wincol + 9,
|
||||
\ 'curscol': wincol + 9,
|
||||
\ 'endcol': wincol + 9}, screenpos(winid, 2, 22))
|
||||
|
||||
let wininfo = getwininfo(winid)[0]
|
||||
call setline(3, ['x']->repeat(wininfo.height))
|
||||
call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3))
|
||||
setlocal nonumber display=lastline so=0
|
||||
exe "normal G\<C-Y>\<C-Y>"
|
||||
redraw
|
||||
call assert_equal({'row': winrow + wininfo.height - 1,
|
||||
\ 'col': wincol + 7,
|
||||
\ 'curscol': wincol + 7,
|
||||
\ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8))
|
||||
call assert_equal({'row': winrow - 1, 'col': 0, 'curscol': 0, 'endcol': 0},
|
||||
\ winid->screenpos(line('$'), 22))
|
||||
|
||||
close
|
||||
call assert_equal({}, screenpos(999, 1, 1))
|
||||
|
||||
bwipe!
|
||||
set display&
|
||||
|
||||
call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1))
|
||||
" nmenu WinBar.TEST :
|
||||
|
Loading…
Reference in New Issue
Block a user