Mercurial > vim
comparison src/testdir/test_popupwin.vim @ 17551:8cca2654d459 v8.1.1773
patch 8.1.1773: the preview popup window may be too far to the right
commit https://github.com/vim/vim/commit/13d5c3f6162694a7e925e66fc4eea35436643384
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 28 21:42:38 2019 +0200
patch 8.1.1773: the preview popup window may be too far to the right
Problem: The preview popup window may be too far to the right.
Solution: Keep it inside the screen. Also keep the close button and
scrollbar visible if possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Jul 2019 21:45:05 +0200 |
parents | 57b9fca8c7d2 |
children | d5e5d0fc3fa8 |
comparison
equal
deleted
inserted
replaced
17550:9afddb85a45c | 17551:8cca2654d459 |
---|---|
1007 call popup_close(winid) | 1007 call popup_close(winid) |
1008 | 1008 |
1009 call cursor(1, 1) | 1009 call cursor(1, 1) |
1010 redraw | 1010 redraw |
1011 let winid = popup_create('vim', #{ | 1011 let winid = popup_create('vim', #{ |
1012 \ line: 'cursor+2', | 1012 \ line: 'cursor+2', |
1013 \ col: 'cursor+1', | 1013 \ col: 'cursor+1', |
1014 \}) | 1014 \}) |
1015 redraw | 1015 redraw |
1016 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') | 1016 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
1017 call assert_equal('xvimxxxxxxxxxxxxx', line) | 1017 call assert_equal('xvimxxxxxxxxxxxxx', line) |
1018 call popup_close(winid) | 1018 call popup_close(winid) |
1019 | 1019 |
1020 call cursor(3, 3) | 1020 call cursor(3, 3) |
1021 redraw | 1021 redraw |
1022 let winid = popup_create('vim', #{ | 1022 let winid = popup_create('vim', #{ |
1023 \ line: 'cursor-2', | 1023 \ line: 'cursor-2', |
1024 \ col: 'cursor-1', | 1024 \ col: 'cursor-1', |
1025 \}) | 1025 \}) |
1026 redraw | 1026 redraw |
1027 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') | 1027 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
1028 call assert_equal('xvimxxxxxxxxxxxxx', line) | 1028 call assert_equal('xvimxxxxxxxxxxxxx', line) |
1029 call popup_close(winid) | 1029 call popup_close(winid) |
1030 | 1030 |
1345 " clean up | 1345 " clean up |
1346 call StopVimInTerminal(buf) | 1346 call StopVimInTerminal(buf) |
1347 call delete('XtestPopupBehind') | 1347 call delete('XtestPopupBehind') |
1348 endfunc | 1348 endfunc |
1349 | 1349 |
1350 func s:VerifyPosition( p, msg, line, col, width, height ) | 1350 func s:VerifyPosition(p, msg, line, col, width, height) |
1351 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' ) | 1351 call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)') |
1352 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' ) | 1352 call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)') |
1353 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' ) | 1353 call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)') |
1354 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' ) | 1354 call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)') |
1355 endfunc | 1355 endfunc |
1356 | 1356 |
1357 func Test_popup_position_adjust() | 1357 func Test_popup_position_adjust() |
1358 " Anything placed past 2 cells from of the right of the screen is moved to the | 1358 " Anything placed past 2 cells from of the right of the screen is moved to the |
1359 " left. | 1359 " left. |
1362 " screen, unless fixed is set. | 1362 " screen, unless fixed is set. |
1363 | 1363 |
1364 " Entries for cases which don't vary based on wrapping. | 1364 " Entries for cases which don't vary based on wrapping. |
1365 " Format is per tests described below | 1365 " Format is per tests described below |
1366 let both_wrap_tests = [ | 1366 let both_wrap_tests = [ |
1367 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ], | 1367 \ ['a', 5, &columns, 5, &columns - 2, 1, 1], |
1368 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ], | 1368 \ ['b', 5, &columns + 1, 5, &columns - 2, 1, 1], |
1369 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ], | 1369 \ ['c', 5, &columns - 1, 5, &columns - 2, 1, 1], |
1370 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ], | 1370 \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1], |
1371 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ], | 1371 \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1], |
1372 \ | 1372 \ |
1373 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ], | 1373 \ ['aa', 5, &columns, 5, &columns - 2, 2, 1], |
1374 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ], | 1374 \ ['bb', 5, &columns + 1, 5, &columns - 2, 2, 1], |
1375 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ], | 1375 \ ['cc', 5, &columns - 1, 5, &columns - 2, 2, 1], |
1376 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ], | 1376 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1], |
1377 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ], | 1377 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1], |
1378 \ | 1378 \ |
1379 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ], | 1379 \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1], |
1380 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], | 1380 \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1], |
1381 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], | 1381 \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1], |
1382 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], | 1382 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1], |
1383 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ], | 1383 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1], |
1384 \ ] | 1384 \ ] |
1385 | 1385 |
1386 " these test groups are dicts with: | 1386 " these test groups are dicts with: |
1387 " - comment: something to identify the group of tests by | 1387 " - comment: something to identify the group of tests by |
1388 " - options: dict of options to merge with the row/col in tests | 1388 " - options: dict of options to merge with the row/col in tests |
1389 " - tests: list of cases. Each one is a list with elements: | 1389 " - tests: list of cases. Each one is a list with elements: |
1393 " - expected row | 1393 " - expected row |
1394 " - expected col | 1394 " - expected col |
1395 " - expected width | 1395 " - expected width |
1396 " - expected height | 1396 " - expected height |
1397 let tests = [ | 1397 let tests = [ |
1398 \ #{ | 1398 \ #{ |
1399 \ comment: 'left-aligned with wrapping', | 1399 \ comment: 'left-aligned with wrapping', |
1400 \ options: #{ | 1400 \ options: #{ |
1401 \ wrap: 1, | 1401 \ wrap: 1, |
1402 \ pos: 'botleft', | 1402 \ pos: 'botleft', |
1403 \ }, | 1403 \ }, |
1404 \ tests: both_wrap_tests + [ | 1404 \ tests: both_wrap_tests + [ |
1405 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ], | 1405 \ ['aaaa', 5, &columns, 4, &columns - 2, 3, 2], |
1406 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ], | 1406 \ ['bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2], |
1407 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ], | 1407 \ ['cccc', 5, &columns - 1, 4, &columns - 2, 3, 2], |
1408 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ], | 1408 \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2], |
1409 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], | 1409 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
1410 \ ], | 1410 \ ], |
1411 \ }, | 1411 \ }, |
1412 \ #{ | 1412 \ #{ |
1413 \ comment: 'left aligned without wrapping', | 1413 \ comment: 'left aligned without wrapping', |
1414 \ options: #{ | 1414 \ options: #{ |
1415 \ wrap: 0, | 1415 \ wrap: 0, |
1416 \ pos: 'botleft', | 1416 \ pos: 'botleft', |
1417 \ }, | 1417 \ }, |
1418 \ tests: both_wrap_tests + [ | 1418 \ tests: both_wrap_tests + [ |
1419 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ], | 1419 \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1], |
1420 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ], | 1420 \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1], |
1421 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ], | 1421 \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1], |
1422 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ], | 1422 \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1], |
1423 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], | 1423 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
1424 \ ], | 1424 \ ], |
1425 \ }, | 1425 \ }, |
1426 \ #{ | 1426 \ #{ |
1427 \ comment: 'left aligned with fixed position', | 1427 \ comment: 'left aligned with fixed position', |
1428 \ options: #{ | 1428 \ options: #{ |
1429 \ wrap: 0, | 1429 \ wrap: 0, |
1430 \ fixed: 1, | 1430 \ fixed: 1, |
1431 \ pos: 'botleft', | 1431 \ pos: 'botleft', |
1432 \ }, | 1432 \ }, |
1433 \ tests: both_wrap_tests + [ | 1433 \ tests: both_wrap_tests + [ |
1434 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ], | 1434 \ ['aaaa', 5, &columns, 5, &columns - 2, 3, 1], |
1435 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], | 1435 \ ['bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1], |
1436 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], | 1436 \ ['cccc', 5, &columns - 1, 5, &columns - 2, 3, 1], |
1437 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], | 1437 \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1], |
1438 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], | 1438 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
1439 \ ], | 1439 \ ], |
1440 \ }, | 1440 \ }, |
1441 \ ] | 1441 \ ] |
1442 | 1442 |
1443 for test_group in tests | 1443 for test_group in tests |
1444 for test in test_group.tests | 1444 for test in test_group.tests |
1445 let [ text, line, col, e_line, e_col, e_width, e_height ] = test | 1445 let [ text, line, col, e_line, e_col, e_width, e_height ] = test |
1446 let options = #{ | 1446 let options = #{ |
1447 \ line: line, | 1447 \ line: line, |
1448 \ col: col, | 1448 \ col: col, |
1449 \ } | 1449 \ } |
1450 call extend( options, test_group.options ) | 1450 call extend(options, test_group.options) |
1451 | 1451 |
1452 let p = popup_create( text, options ) | 1452 let p = popup_create(text, options) |
1453 | 1453 |
1454 let msg = string(extend(options, #{text: text})) | 1454 let msg = string(extend(options, #{text: text})) |
1455 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height) | 1455 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height) |
1456 call popup_close(p) | 1456 call popup_close(p) |
1457 endfor | 1457 endfor |
1463 | 1463 |
1464 func Test_adjust_left_past_screen_width() | 1464 func Test_adjust_left_past_screen_width() |
1465 " width of screen | 1465 " width of screen |
1466 let X = join(map(range(&columns), {->'X'}), '') | 1466 let X = join(map(range(&columns), {->'X'}), '') |
1467 | 1467 |
1468 let p = popup_create( X, #{line: 1, col: 1, wrap: 0}) | 1468 let p = popup_create(X, #{line: 1, col: 1, wrap: 0}) |
1469 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 ) | 1469 call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1) |
1470 | 1470 |
1471 redraw | 1471 redraw |
1472 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') | 1472 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
1473 call assert_equal(X, line) | 1473 call assert_equal(X, line) |
1474 | 1474 |
1475 call popup_close( p ) | 1475 call popup_close(p) |
1476 redraw | 1476 redraw |
1477 | 1477 |
1478 " Same if placed on the right hand side | 1478 " Same if placed on the right hand side |
1479 let p = popup_create( X, #{line: 1, col: &columns, wrap: 0}) | 1479 let p = popup_create(X, #{line: 1, col: &columns, wrap: 0}) |
1480 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 ) | 1480 call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1) |
1481 | 1481 |
1482 redraw | 1482 redraw |
1483 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') | 1483 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
1484 call assert_equal(X, line) | 1484 call assert_equal(X, line) |
1485 | 1485 |
1486 call popup_close( p ) | 1486 call popup_close(p) |
1487 redraw | 1487 redraw |
1488 | 1488 |
1489 " Extend so > window width | 1489 " Extend so > window width |
1490 let X .= 'x' | 1490 let X .= 'x' |
1491 | 1491 |
1492 let p = popup_create( X, #{line: 1, col: 1, wrap: 0}) | 1492 let p = popup_create(X, #{line: 1, col: 1, wrap: 0}) |
1493 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 ) | 1493 call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1) |
1494 | 1494 |
1495 redraw | 1495 redraw |
1496 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') | 1496 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
1497 call assert_equal(X[ : -2 ], line) | 1497 call assert_equal(X[ : -2 ], line) |
1498 | 1498 |
1499 call popup_close( p ) | 1499 call popup_close(p) |
1500 redraw | 1500 redraw |
1501 | 1501 |
1502 " Shifted then truncated (the x is not visible) | 1502 " Shifted then truncated (the x is not visible) |
1503 let p = popup_create( X, #{line: 1, col: &columns - 3, wrap: 0}) | 1503 let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0}) |
1504 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 ) | 1504 call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1) |
1505 | 1505 |
1506 redraw | 1506 redraw |
1507 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') | 1507 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
1508 call assert_equal(X[ : -2 ], line) | 1508 call assert_equal(X[ : -2 ], line) |
1509 | 1509 |
1510 call popup_close( p ) | 1510 call popup_close(p) |
1511 redraw | 1511 redraw |
1512 | 1512 |
1513 " Not shifted, just truncated | 1513 " Not shifted, just truncated |
1514 let p = popup_create( X, | 1514 let p = popup_create(X, |
1515 \ #{line: 1, col: 2, wrap: 0, fixed: 1}) | 1515 \ #{line: 1, col: 2, wrap: 0, fixed: 1}) |
1516 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) | 1516 call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) |
1517 | 1517 |
1518 redraw | 1518 redraw |
1519 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') | 1519 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
1520 let e_line = ' ' . X[ 1 : -2 ] | 1520 let e_line = ' ' . X[ 1 : -2 ] |
1521 call assert_equal(e_line, line) | 1521 call assert_equal(e_line, line) |
1522 | 1522 |
1523 call popup_close( p ) | 1523 call popup_close(p) |
1524 redraw | 1524 redraw |
1525 | 1525 |
1526 call popup_clear() | 1526 call popup_clear() |
1527 %bwipe! | 1527 %bwipe! |
1528 endfunc | 1528 endfunc |
1713 let opts = #{wrap: 0} | 1713 let opts = #{wrap: 0} |
1714 let p = popup_create('test', opts) | 1714 let p = popup_create('test', opts) |
1715 call popup_settext(p, 'this is a text') | 1715 call popup_settext(p, 'this is a text') |
1716 END | 1716 END |
1717 | 1717 |
1718 call writefile( lines, 'XtestPopupSetText' ) | 1718 call writefile(lines, 'XtestPopupSetText') |
1719 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10}) | 1719 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10}) |
1720 call VerifyScreenDump(buf, 'Test_popup_settext_01', {}) | 1720 call VerifyScreenDump(buf, 'Test_popup_settext_01', {}) |
1721 | 1721 |
1722 " Setting to empty string clears it | 1722 " Setting to empty string clears it |
1723 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>") | 1723 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>") |
2153 \ + range(29, 40), | 2153 \ + range(29, 40), |
2154 \ "Xtagfile") | 2154 \ "Xtagfile") |
2155 let lines =<< trim END | 2155 let lines =<< trim END |
2156 set tags=Xtags | 2156 set tags=Xtags |
2157 call setline(1, [ | 2157 call setline(1, [ |
2158 \ 'one', | 2158 \ 'one', |
2159 \ 'two', | 2159 \ 'two', |
2160 \ 'three', | 2160 \ 'three', |
2161 \ 'four', | 2161 \ 'four', |
2162 \ 'five', | 2162 \ 'five', |
2163 \ 'six', | 2163 \ 'six', |
2164 \ 'seven', | 2164 \ 'seven', |
2165 \ 'find theword somewhere', | 2165 \ 'find theword somewhere', |
2166 \ 'nine', | 2166 \ 'nine', |
2167 \ 'this is another word']) | 2167 \ 'this is another word', |
2168 \ 'very long line where the word is also another']) | |
2168 set previewpopup=height:4,width:40 | 2169 set previewpopup=height:4,width:40 |
2169 END | 2170 END |
2170 call writefile(lines, 'XtestPreviewPopup') | 2171 call writefile(lines, 'XtestPreviewPopup') |
2171 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14}) | 2172 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14}) |
2172 | 2173 |
2175 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {}) | 2176 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {}) |
2176 | 2177 |
2177 call term_sendkeys(buf, "/another\<CR>\<C-W>}") | 2178 call term_sendkeys(buf, "/another\<CR>\<C-W>}") |
2178 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {}) | 2179 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {}) |
2179 | 2180 |
2181 call term_sendkeys(buf, ":call popup_move(popup_getpreview(), #{col: 15})\<CR>") | |
2182 call term_sendkeys(buf, ":\<CR>") | |
2183 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {}) | |
2184 | |
2185 call term_sendkeys(buf, "/another\<CR>\<C-W>}") | |
2186 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {}) | |
2187 | |
2180 call StopVimInTerminal(buf) | 2188 call StopVimInTerminal(buf) |
2181 call delete('Xtags') | 2189 call delete('Xtags') |
2182 call delete('Xtagfile') | 2190 call delete('Xtagfile') |
2183 call delete('XtestPreviewPopup') | 2191 call delete('XtestPreviewPopup') |
2184 endfunc | 2192 endfunc |