diff options
-rw-r--r-- | src/nvim/buffer.c | 4 | ||||
-rw-r--r-- | src/nvim/terminal.c | 9 | ||||
-rw-r--r-- | src/nvim/window.c | 4 | ||||
-rw-r--r-- | test/functional/terminal/mouse_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/terminal/window_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/terminal/window_split_tab_spec.lua | 127 |
6 files changed, 84 insertions, 107 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 72724b0ffd..438a85dd5d 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1249,6 +1249,10 @@ void enter_buffer(buf_T *buf) /* mark cursor position as being invalid */ curwin->w_valid = 0; + if (buf->terminal) { + terminal_resize(buf->terminal, curwin->w_width, curwin->w_height); + } + /* Make sure the buffer is loaded. */ if (curbuf->b_ml.ml_mfp == NULL) { /* need to load the file */ /* If there is no filetype, allow for detecting one. Esp. useful for diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 3e41926b70..fd416b3dcc 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -348,15 +348,6 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) height = (uint16_t)curheight; } - // The new width/height are the minimum for all windows that display the - // terminal in the current tab. - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (!wp->w_closing && wp->w_buffer->terminal == term) { - width = (uint16_t)MIN(width, (uint16_t)(wp->w_width - win_col_off(wp))); - height = (uint16_t)MIN(height, (uint16_t)wp->w_height); - } - } - if (curheight == height && curwidth == width) { return; } diff --git a/src/nvim/window.c b/src/nvim/window.c index bea55c465f..4eaba3a3df 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3613,6 +3613,10 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri /* Change directories when the 'acd' option is set. */ do_autochdir(); + + if (curbuf->terminal) { + terminal_resize(curbuf->terminal, curwin->w_width, curwin->w_height); + } } diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 0ac7165d6a..a86615184d 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -112,7 +112,7 @@ describe('terminal mouse', function() line28 |line28 | line29 |line29 | line30 |line30 | - rows: 5, cols: 24 |rows: 5, cols: 24 | + rows: 5, cols: 25 |rows: 5, cols: 25 | {2:^ } |{2: } | ========== ========== | | @@ -122,7 +122,7 @@ describe('terminal mouse', function() 1 ^ |line28 | ~ |line29 | ~ |line30 | - ~ |rows: 5, cols: 24 | + ~ |rows: 5, cols: 25 | ~ |{2: } | ========== ========== | :enew | set number | @@ -132,16 +132,16 @@ describe('terminal mouse', function() 27 line |line28 | 28 line |line29 | 29 line |line30 | - 30 line |rows: 5, cols: 24 | + 30 line |rows: 5, cols: 25 | 31 ^ |{2: } | ========== ========== | | ]]) feed('<c-w>li') screen:expect([[ - 27 line |line28 | - 28 line |line29 | - 29 line |line30 | + 27 line |line29 | + 28 line |line30 | + 29 line |rows: 5, cols: 25 | 30 line |rows: 5, cols: 24 | 31 |{1: } | ========== ========== | @@ -151,8 +151,8 @@ describe('terminal mouse', function() thelpers.enable_mouse() thelpers.feed_data('mouse enabled\n') screen:expect([[ - 27 line |line29 | - 28 line |line30 | + 27 line |line30 | + 28 line |rows: 5, cols: 25 | 29 line |rows: 5, cols: 24 | 30 line |mouse enabled | 31 |{1: } | @@ -164,8 +164,8 @@ describe('terminal mouse', function() it('wont lose focus if another window is scrolled', function() feed('<MouseDown><0,0><MouseDown><0,0>') screen:expect([[ - 21 line |line29 | - 22 line |line30 | + 21 line |line30 | + 22 line |rows: 5, cols: 25 | 23 line |rows: 5, cols: 24 | 24 line |mouse enabled | 25 line |{1: } | @@ -174,8 +174,8 @@ describe('terminal mouse', function() ]]) feed('<S-MouseUp><0,0>') screen:expect([[ - 26 line |line29 | - 27 line |line30 | + 26 line |line30 | + 27 line |rows: 5, cols: 25 | 28 line |rows: 5, cols: 24 | 29 line |mouse enabled | 30 line |{1: } | @@ -187,8 +187,8 @@ describe('terminal mouse', function() it('will lose focus if another window is clicked', function() feed('<LeftMouse><5,1>') screen:expect([[ - 27 line |line29 | - 28 l^ine |line30 | + 27 line |line30 | + 28 l^ine |rows: 5, cols: 25 | 29 line |rows: 5, cols: 24 | 30 line |mouse enabled | 31 |{2: } | diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 7bc739c548..eec8b53f4d 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local feed, clear = helpers.feed, helpers.clear local wait = helpers.wait - +local execute = helpers.execute describe('terminal window', function() local screen @@ -12,6 +12,23 @@ describe('terminal window', function() screen = thelpers.screen_setup() end) + it('resets its size when entering terminal buffer', function() + feed('<c-\\><c-n>') + execute('set hidden') + execute('edit foo') + execute('doautoall SessionLoadPost') + execute('silent bnext') + screen:expect([[ + tty ready | + {2: } | + | + | + | + ^ | + :silent bnext | + ]]) + end) + describe('with colorcolumn set', function() before_each(function() feed('<c-\\><c-n>') diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 3696332940..644060103a 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear = helpers.clear local feed, nvim = helpers.feed, helpers.nvim +local execute = helpers.execute describe('terminal', function() local screen @@ -21,6 +22,49 @@ describe('terminal', function() screen:detach() end) + it('resets its size when entering terminal window', function() + feed('<c-\\><c-n>') + execute('2split') + screen:expect([[ + tty ready | + ^rows: 2, cols: 50 | + ========== | + tty ready | + rows: 2, cols: 50 | + {2: } | + ~ | + ~ | + ========== | + | + ]]) + execute('wincmd p') + screen:expect([[ + tty ready | + rows: 2, cols: 50 | + ========== | + tty ready | + rows: 2, cols: 50 | + rows: 5, cols: 50 | + {2: } | + ^ | + ========== | + :wincmd p | + ]]) + execute('wincmd p') + screen:expect([[ + rows: 5, cols: 50 | + ^rows: 2, cols: 50 | + ========== | + rows: 5, cols: 50 | + rows: 2, cols: 50 | + {2: } | + ~ | + ~ | + ========== | + :wincmd p | + ]]) + end) + describe('when the screen is resized', function() it('will forward a resize request to the program', function() screen:try_resize(screen._width + 3, screen._height + 5) @@ -51,87 +95,4 @@ describe('terminal', function() ]]) end) end) - - describe('split horizontally', function() - before_each(function() - nvim('command', 'sp') - end) - - local function reduce_height() - screen:expect([[ - tty ready | - rows: 3, cols: 50 | - {1: } | - ~ | - ========== | - tty ready | - rows: 3, cols: 50 | - {2: } | - ========== | - -- TERMINAL -- | - ]]) - end - - it('uses the minimum height of all window displaying it', reduce_height) - - describe('and then vertically', function() - before_each(function() - reduce_height() - nvim('command', 'vsp') - end) - - local function reduce_width() - screen:expect([[ - rows: 3, cols: 50 |rows: 3, cols: 50 | - rows: 3, cols: 24 |rows: 3, cols: 24 | - {1: } |{2: } | - ~ |~ | - ========== ========== | - rows: 3, cols: 50 | - rows: 3, cols: 24 | - {2: } | - ========== | - -- TERMINAL -- | - ]]) - feed('<c-\\><c-n>gg') - screen:expect([[ - ^tty ready |rows: 3, cols: 50 | - rows: 3, cols: 50 |rows: 3, cols: 24 | - rows: 3, cols: 24 |{2: } | - {2: } |~ | - ========== ========== | - rows: 3, cols: 50 | - rows: 3, cols: 24 | - {2: } | - ========== | - | - ]]) - end - - it('uses the minimum width of all window displaying it', reduce_width) - - describe('and then closes one of the vertical splits with q:', function() - before_each(function() - reduce_width() - nvim('command', 'q') - feed('<c-w>ja') - end) - - it('will restore the width', function() - screen:expect([[ - rows: 3, cols: 24 | - rows: 3, cols: 50 | - {2: } | - ~ | - ========== | - rows: 3, cols: 24 | - rows: 3, cols: 50 | - {1: } | - ========== | - -- TERMINAL -- | - ]]) - end) - end) - end) - end) end) |