mirror of
https://github.com/neovim/neovim
synced 2025-07-27 08:52:10 +00:00
:terminal : set topline based on window height #8325
This commit is contained in:
@ -1304,8 +1304,6 @@ static void redraw(bool restore_cursor)
|
|||||||
|
|
||||||
static void adjust_topline(Terminal *term, buf_T *buf, long added)
|
static void adjust_topline(Terminal *term, buf_T *buf, long added)
|
||||||
{
|
{
|
||||||
int height, width;
|
|
||||||
vterm_get_size(term->vt, &height, &width);
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
if (wp->w_buffer == buf) {
|
if (wp->w_buffer == buf) {
|
||||||
linenr_T ml_end = buf->b_ml.ml_line_count;
|
linenr_T ml_end = buf->b_ml.ml_line_count;
|
||||||
@ -1314,7 +1312,7 @@ static void adjust_topline(Terminal *term, buf_T *buf, long added)
|
|||||||
if (following || (wp == curwin && is_focused(term))) {
|
if (following || (wp == curwin && is_focused(term))) {
|
||||||
// "Follow" the terminal output
|
// "Follow" the terminal output
|
||||||
wp->w_cursor.lnum = ml_end;
|
wp->w_cursor.lnum = ml_end;
|
||||||
set_topline(wp, MAX(wp->w_cursor.lnum - height + 1, 1));
|
set_topline(wp, MAX(wp->w_cursor.lnum - wp->w_height + 1, 1));
|
||||||
} else {
|
} else {
|
||||||
// Ensure valid cursor for each window displaying this terminal.
|
// Ensure valid cursor for each window displaying this terminal.
|
||||||
wp->w_cursor.lnum = MIN(wp->w_cursor.lnum, ml_end);
|
wp->w_cursor.lnum = MIN(wp->w_cursor.lnum, ml_end);
|
||||||
|
@ -8,7 +8,7 @@ local exit_altscreen = thelpers.exit_altscreen
|
|||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
describe('terminal altscreen', function()
|
describe(':terminal altscreen', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -6,7 +6,7 @@ local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.s
|
|||||||
local eq, neq = helpers.eq, helpers.neq
|
local eq, neq = helpers.eq, helpers.neq
|
||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
|
|
||||||
describe('terminal buffer', function()
|
describe(':terminal buffer', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -7,7 +7,7 @@ local feed_command = helpers.feed_command
|
|||||||
local hide_cursor = thelpers.hide_cursor
|
local hide_cursor = thelpers.hide_cursor
|
||||||
local show_cursor = thelpers.show_cursor
|
local show_cursor = thelpers.show_cursor
|
||||||
|
|
||||||
describe('terminal cursor', function()
|
describe(':terminal cursor', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -5,7 +5,7 @@ local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
|
|||||||
local nvim_dir, command = helpers.nvim_dir, helpers.command
|
local nvim_dir, command = helpers.nvim_dir, helpers.command
|
||||||
local eq, eval = helpers.eq, helpers.eval
|
local eq, eval = helpers.eq, helpers.eval
|
||||||
|
|
||||||
describe('terminal window highlighting', function()
|
describe(':terminal window highlighting', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -4,7 +4,7 @@ local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval
|
|||||||
local feed, nvim = helpers.feed, helpers.nvim
|
local feed, nvim = helpers.feed, helpers.nvim
|
||||||
local feed_data = thelpers.feed_data
|
local feed_data = thelpers.feed_data
|
||||||
|
|
||||||
describe('terminal mouse', function()
|
describe(':terminal mouse', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -12,7 +12,7 @@ local curbufmeths = helpers.curbufmeths
|
|||||||
local nvim = helpers.nvim
|
local nvim = helpers.nvim
|
||||||
local feed_data = thelpers.feed_data
|
local feed_data = thelpers.feed_data
|
||||||
|
|
||||||
describe('terminal scrollback', function()
|
describe(':terminal scrollback', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@ -344,7 +344,7 @@ describe('terminal scrollback', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('terminal prints more lines than the screen height and exits', function()
|
describe(':terminal prints more lines than the screen height and exits', function()
|
||||||
it('will push extra lines to scrollback', function()
|
it('will push extra lines to scrollback', function()
|
||||||
clear()
|
clear()
|
||||||
local screen = Screen.new(30, 7)
|
local screen = Screen.new(30, 7)
|
||||||
@ -460,7 +460,7 @@ describe("'scrollback' option", function()
|
|||||||
screen:detach()
|
screen:detach()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('defaults to 10000 in terminal buffers', function()
|
it('defaults to 10000 in :terminal buffers', function()
|
||||||
set_fake_shell()
|
set_fake_shell()
|
||||||
command('terminal')
|
command('terminal')
|
||||||
eq(10000, curbufmeths.get_option('scrollback'))
|
eq(10000, curbufmeths.get_option('scrollback'))
|
||||||
|
@ -20,7 +20,7 @@ local read_file = helpers.read_file
|
|||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
describe('tui', function()
|
describe('TUI', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
@ -3,8 +3,12 @@ local thelpers = require('test.functional.terminal.helpers')
|
|||||||
local feed, clear = helpers.feed, helpers.clear
|
local feed, clear = helpers.feed, helpers.clear
|
||||||
local wait = helpers.wait
|
local wait = helpers.wait
|
||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
|
local command = helpers.command
|
||||||
|
local retry = helpers.retry
|
||||||
|
local eq = helpers.eq
|
||||||
|
local eval = helpers.eval
|
||||||
|
|
||||||
describe('terminal window', function()
|
describe(':terminal window', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@ -12,6 +16,19 @@ describe('terminal window', function()
|
|||||||
screen = thelpers.screen_setup()
|
screen = thelpers.screen_setup()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('sets topline correctly #8556', function()
|
||||||
|
-- Test has hardcoded assumptions of dimensions.
|
||||||
|
eq(7, eval('&lines'))
|
||||||
|
command('set shell=sh')
|
||||||
|
command('terminal')
|
||||||
|
retry(nil, nil, function() assert(nil ~= eval('b:terminal_job_pid')) end)
|
||||||
|
-- Terminal/shell contents must exceed the height of this window.
|
||||||
|
command('topleft 1split')
|
||||||
|
feed([[i<cr>]])
|
||||||
|
-- Check topline _while_ in terminal-mode.
|
||||||
|
retry(nil, nil, function() eq(6, eval('winsaveview()["topline"]')) end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("with 'number'", function()
|
describe("with 'number'", function()
|
||||||
it('wraps text', function()
|
it('wraps text', function()
|
||||||
feed([[<C-\><C-N>]])
|
feed([[<C-\><C-N>]])
|
||||||
|
@ -9,7 +9,7 @@ local eval = helpers.eval
|
|||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
|
|
||||||
describe('terminal', function()
|
describe(':terminal', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
Reference in New Issue
Block a user