terminal: handle size when switching buffers in window

This commit is contained in:
Björn Linse 2019-01-26 12:37:38 +01:00
parent 2ab70cb55c
commit 30bd1c1e85
8 changed files with 76 additions and 30 deletions

View File

@ -1472,6 +1472,10 @@ void set_curbuf(buf_T *buf, int action)
if (old_tw != curbuf->b_p_tw)
check_colorcolumn(curwin);
}
if (bufref_valid(&prevbufref) && prevbuf->terminal != NULL) {
terminal_check_size(prevbuf->terminal);
}
}
/*

View File

@ -1034,10 +1034,13 @@ struct window_S {
int w_width; /* Width of window, excluding separation. */
int w_vsep_width; /* Number of separator columns (0 or 1). */
// inner size of window, which can be overriden by external UI
int w_height_inner;
int w_width_inner;
// external UI request. If non-zero, the inner size will use this.
int w_height_request;
int w_width_request;
/*
* === start of cached values ====
*/

View File

@ -2678,6 +2678,10 @@ int do_ecmd(
theend:
if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->terminal != NULL) {
terminal_check_size(old_curbuf.br_buf->terminal);
}
if (did_inc_redrawing_disabled) {
RedrawingDisabled--;
}

View File

@ -1452,7 +1452,8 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
curwin->w_topline = loff.lnum) {
loff.lnum = curwin->w_topline;
topline_back(&loff);
if (loff.height == MAXCOL || used + loff.height > curwin->w_height_inner) {
if (loff.height == MAXCOL
|| used + loff.height > curwin->w_height_inner) {
break;
}
used += loff.height;

View File

@ -337,19 +337,16 @@ void terminal_close(Terminal *term, char *msg)
void terminal_check_size(Terminal *term)
{
if (term->closed) {
// TODO: WTF does this mean:
// If two windows display the same terminal and one is closed by keypress.
return;
}
int curwidth, curheight;
vterm_get_size(term->vt, &curheight, &curwidth);
uint16_t width = 0, height = 0;
bool window_seen = false;
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer && wp->w_buffer->terminal == term) {
window_seen = true;
const uint16_t win_width =
(uint16_t)(MAX(0, wp->w_width_inner - win_col_off(wp)));
width = MAX(width, win_width);
@ -357,6 +354,8 @@ void terminal_check_size(Terminal *term)
}
}
// if no window displays the terminal, or such all windows are zero-height,
// don't resize the terminal.
if ((curheight == height && curwidth == width) || height == 0 || width == 0) {
return;
}

View File

@ -453,7 +453,7 @@ void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error)
}
// non-positive indicates no request
wp->w_height_request = (int)MAX(height,0);
wp->w_width_request = (int)MAX(width,0);
wp->w_height_request = (int)MAX(height, 0);
wp->w_width_request = (int)MAX(width, 0);
win_set_inner_size(wp);
}

View File

@ -4126,7 +4126,7 @@ void win_alloc_lines(win_T *wp)
{
wp->w_lines_valid = 0;
assert(wp->w_height_inner >= 0);
// TODO(bfredl) :this should work, add call to win_set_inner_size?
// TODO(bfredl): this should work, add call to win_set_inner_size?
// wp->w_lines = xcalloc(wp->w_height_inner+1, sizeof(wline_T));
wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T));
}

View File

@ -108,41 +108,42 @@ describe('terminal mouse', function()
]])
feed(':enew | set number<cr>')
screen:expect([[
{7: 1 }^ line28 |
{4:~ }line29 |
{7: 1 }^ line29 |
{4:~ }line30 |
{4:~ }rows: 5, cols: 25 |
{4:~ }rows: 5, cols: 24 |
{4:~ }{2: } |
========== ========== |
:enew | set number |
]])
feed('30iline\n<esc>')
screen:expect([[
{7: 27 }line line28 |
{7: 28 }line line29 |
{7: 29 }line line30 |
{7: 30 }line rows: 5, cols: 25 |
{7: 27 }line line29 |
{7: 28 }line line30 |
{7: 29 }line rows: 5, cols: 25 |
{7: 30 }line rows: 5, cols: 24 |
{7: 31 }^ {2: } |
========== ========== |
|
]])
feed('<c-w>li')
screen:expect([[
{7: 27 }line line28 |
{7: 28 }line line29 |
{7: 29 }line line30 |
{7: 30 }line rows: 5, cols: 25 |
{7: 27 }line line29 |
{7: 28 }line line30 |
{7: 29 }line rows: 5, cols: 25 |
{7: 30 }line rows: 5, cols: 24 |
{7: 31 } {1: } |
========== ========== |
{3:-- TERMINAL --} |
]])
-- enabling mouse won't affect interaction with other windows
thelpers.enable_mouse()
thelpers.feed_data('mouse enabled\n')
screen:expect([[
{7: 27 }line line29 |
{7: 28 }line line30 |
{7: 29 }line rows: 5, cols: 25 |
{7: 27 }line line30 |
{7: 28 }line rows: 5, cols: 25 |
{7: 29 }line rows: 5, cols: 24 |
{7: 30 }line mouse enabled |
{7: 31 } {1: } |
========== ========== |
@ -153,9 +154,9 @@ describe('terminal mouse', function()
it('wont lose focus if another window is scrolled', function()
feed('<ScrollWheelUp><0,0><ScrollWheelUp><0,0>')
screen:expect([[
{7: 21 }line line29 |
{7: 22 }line line30 |
{7: 23 }line rows: 5, cols: 25 |
{7: 21 }line line30 |
{7: 22 }line rows: 5, cols: 25 |
{7: 23 }line rows: 5, cols: 24 |
{7: 24 }line mouse enabled |
{7: 25 }line {1: } |
========== ========== |
@ -163,9 +164,9 @@ describe('terminal mouse', function()
]])
feed('<S-ScrollWheelDown><0,0>')
screen:expect([[
{7: 26 }line line29 |
{7: 27 }line line30 |
{7: 28 }line rows: 5, cols: 25 |
{7: 26 }line line30 |
{7: 27 }line rows: 5, cols: 25 |
{7: 28 }line rows: 5, cols: 24 |
{7: 29 }line mouse enabled |
{7: 30 }line {1: } |
========== ========== |
@ -176,15 +177,49 @@ describe('terminal mouse', function()
it('will lose focus if another window is clicked', function()
feed('<LeftMouse><5,1>')
screen:expect([[
{7: 27 }line line29 |
{7: 28 }l^ine line30 |
{7: 29 }line rows: 5, cols: 25 |
{7: 27 }line line30 |
{7: 28 }l^ine rows: 5, cols: 25 |
{7: 29 }line rows: 5, cols: 24 |
{7: 30 }line mouse enabled |
{7: 31 } {2: } |
========== ========== |
|
]])
end)
it('handles terminal size when switching buffers', function()
nvim('set_option', 'hidden', true)
feed('<c-\\><c-n><c-w><c-w>')
screen:expect([[
{7: 27 }line line30 |
{7: 28 }line rows: 5, cols: 25 |
{7: 29 }line rows: 5, cols: 24 |
{7: 30 }line mouse enabled |
{7: 31 }^ {2: } |
========== ========== |
|
]])
feed(':bn<cr>')
screen:expect([[
rows: 5, cols: 25 rows: 5, cols: 25 |
rows: 5, cols: 24 rows: 5, cols: 24 |
mouse enabled mouse enabled |
rows: 5, cols: 25 rows: 5, cols: 25 |
{2:^ } {2: } |
========== ========== |
:bn |
]])
feed(':bn<cr>')
screen:expect([[
{7: 27 }line rows: 5, cols: 24 |
{7: 28 }line mouse enabled |
{7: 29 }line rows: 5, cols: 25 |
{7: 30 }line rows: 5, cols: 24 |
{7: 31 }^ {2: } |
========== ========== |
:bn |
]])
end)
end)
end)
end)