mirror of
https://github.com/neovim/neovim.git
synced 2025-09-11 13:58:18 +00:00
terminal: handle size when switching buffers in window
This commit is contained in:
@@ -1472,6 +1472,10 @@ void set_curbuf(buf_T *buf, int action)
|
|||||||
if (old_tw != curbuf->b_p_tw)
|
if (old_tw != curbuf->b_p_tw)
|
||||||
check_colorcolumn(curwin);
|
check_colorcolumn(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bufref_valid(&prevbufref) && prevbuf->terminal != NULL) {
|
||||||
|
terminal_check_size(prevbuf->terminal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1034,10 +1034,13 @@ struct window_S {
|
|||||||
int w_width; /* Width of window, excluding separation. */
|
int w_width; /* Width of window, excluding separation. */
|
||||||
int w_vsep_width; /* Number of separator columns (0 or 1). */
|
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_height_inner;
|
||||||
int w_width_inner;
|
int w_width_inner;
|
||||||
|
// external UI request. If non-zero, the inner size will use this.
|
||||||
int w_height_request;
|
int w_height_request;
|
||||||
int w_width_request;
|
int w_width_request;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* === start of cached values ====
|
* === start of cached values ====
|
||||||
*/
|
*/
|
||||||
|
@@ -2678,6 +2678,10 @@ int do_ecmd(
|
|||||||
|
|
||||||
|
|
||||||
theend:
|
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) {
|
if (did_inc_redrawing_disabled) {
|
||||||
RedrawingDisabled--;
|
RedrawingDisabled--;
|
||||||
}
|
}
|
||||||
|
@@ -1452,7 +1452,8 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
|
|||||||
curwin->w_topline = loff.lnum) {
|
curwin->w_topline = loff.lnum) {
|
||||||
loff.lnum = curwin->w_topline;
|
loff.lnum = curwin->w_topline;
|
||||||
topline_back(&loff);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
used += loff.height;
|
used += loff.height;
|
||||||
|
@@ -337,19 +337,16 @@ void terminal_close(Terminal *term, char *msg)
|
|||||||
void terminal_check_size(Terminal *term)
|
void terminal_check_size(Terminal *term)
|
||||||
{
|
{
|
||||||
if (term->closed) {
|
if (term->closed) {
|
||||||
// TODO: WTF does this mean:
|
|
||||||
// If two windows display the same terminal and one is closed by keypress.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int curwidth, curheight;
|
int curwidth, curheight;
|
||||||
vterm_get_size(term->vt, &curheight, &curwidth);
|
vterm_get_size(term->vt, &curheight, &curwidth);
|
||||||
uint16_t width = 0, height = 0;
|
uint16_t width = 0, height = 0;
|
||||||
|
|
||||||
bool window_seen = false;
|
|
||||||
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||||
if (wp->w_buffer && wp->w_buffer->terminal == term) {
|
if (wp->w_buffer && wp->w_buffer->terminal == term) {
|
||||||
window_seen = true;
|
|
||||||
const uint16_t win_width =
|
const uint16_t win_width =
|
||||||
(uint16_t)(MAX(0, wp->w_width_inner - win_col_off(wp)));
|
(uint16_t)(MAX(0, wp->w_width_inner - win_col_off(wp)));
|
||||||
width = MAX(width, win_width);
|
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) {
|
if ((curheight == height && curwidth == width) || height == 0 || width == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -453,7 +453,7 @@ void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// non-positive indicates no request
|
// non-positive indicates no request
|
||||||
wp->w_height_request = (int)MAX(height,0);
|
wp->w_height_request = (int)MAX(height, 0);
|
||||||
wp->w_width_request = (int)MAX(width,0);
|
wp->w_width_request = (int)MAX(width, 0);
|
||||||
win_set_inner_size(wp);
|
win_set_inner_size(wp);
|
||||||
}
|
}
|
||||||
|
@@ -4126,7 +4126,7 @@ void win_alloc_lines(win_T *wp)
|
|||||||
{
|
{
|
||||||
wp->w_lines_valid = 0;
|
wp->w_lines_valid = 0;
|
||||||
assert(wp->w_height_inner >= 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(wp->w_height_inner+1, sizeof(wline_T));
|
||||||
wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T));
|
wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T));
|
||||||
}
|
}
|
||||||
|
@@ -108,41 +108,42 @@ describe('terminal mouse', function()
|
|||||||
]])
|
]])
|
||||||
feed(':enew | set number<cr>')
|
feed(':enew | set number<cr>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 1 }^ │line28 |
|
{7: 1 }^ │line29 |
|
||||||
{4:~ }│line29 |
|
|
||||||
{4:~ }│line30 |
|
{4:~ }│line30 |
|
||||||
{4:~ }│rows: 5, cols: 25 |
|
{4:~ }│rows: 5, cols: 25 |
|
||||||
|
{4:~ }│rows: 5, cols: 24 |
|
||||||
{4:~ }│{2: } |
|
{4:~ }│{2: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
:enew | set number |
|
:enew | set number |
|
||||||
]])
|
]])
|
||||||
feed('30iline\n<esc>')
|
feed('30iline\n<esc>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 27 }line │line28 |
|
{7: 27 }line │line29 |
|
||||||
{7: 28 }line │line29 |
|
{7: 28 }line │line30 |
|
||||||
{7: 29 }line │line30 |
|
{7: 29 }line │rows: 5, cols: 25 |
|
||||||
{7: 30 }line │rows: 5, cols: 25 |
|
{7: 30 }line │rows: 5, cols: 24 |
|
||||||
{7: 31 }^ │{2: } |
|
{7: 31 }^ │{2: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('<c-w>li')
|
feed('<c-w>li')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 27 }line │line28 |
|
{7: 27 }line │line29 |
|
||||||
{7: 28 }line │line29 |
|
{7: 28 }line │line30 |
|
||||||
{7: 29 }line │line30 |
|
{7: 29 }line │rows: 5, cols: 25 |
|
||||||
{7: 30 }line │rows: 5, cols: 25 |
|
{7: 30 }line │rows: 5, cols: 24 |
|
||||||
{7: 31 } │{1: } |
|
{7: 31 } │{1: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
{3:-- TERMINAL --} |
|
{3:-- TERMINAL --} |
|
||||||
]])
|
]])
|
||||||
|
|
||||||
-- enabling mouse won't affect interaction with other windows
|
-- enabling mouse won't affect interaction with other windows
|
||||||
thelpers.enable_mouse()
|
thelpers.enable_mouse()
|
||||||
thelpers.feed_data('mouse enabled\n')
|
thelpers.feed_data('mouse enabled\n')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 27 }line │line29 |
|
{7: 27 }line │line30 |
|
||||||
{7: 28 }line │line30 |
|
{7: 28 }line │rows: 5, cols: 25 |
|
||||||
{7: 29 }line │rows: 5, cols: 25 |
|
{7: 29 }line │rows: 5, cols: 24 |
|
||||||
{7: 30 }line │mouse enabled |
|
{7: 30 }line │mouse enabled |
|
||||||
{7: 31 } │{1: } |
|
{7: 31 } │{1: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
@@ -153,9 +154,9 @@ describe('terminal mouse', function()
|
|||||||
it('wont lose focus if another window is scrolled', function()
|
it('wont lose focus if another window is scrolled', function()
|
||||||
feed('<ScrollWheelUp><0,0><ScrollWheelUp><0,0>')
|
feed('<ScrollWheelUp><0,0><ScrollWheelUp><0,0>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 21 }line │line29 |
|
{7: 21 }line │line30 |
|
||||||
{7: 22 }line │line30 |
|
{7: 22 }line │rows: 5, cols: 25 |
|
||||||
{7: 23 }line │rows: 5, cols: 25 |
|
{7: 23 }line │rows: 5, cols: 24 |
|
||||||
{7: 24 }line │mouse enabled |
|
{7: 24 }line │mouse enabled |
|
||||||
{7: 25 }line │{1: } |
|
{7: 25 }line │{1: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
@@ -163,9 +164,9 @@ describe('terminal mouse', function()
|
|||||||
]])
|
]])
|
||||||
feed('<S-ScrollWheelDown><0,0>')
|
feed('<S-ScrollWheelDown><0,0>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 26 }line │line29 |
|
{7: 26 }line │line30 |
|
||||||
{7: 27 }line │line30 |
|
{7: 27 }line │rows: 5, cols: 25 |
|
||||||
{7: 28 }line │rows: 5, cols: 25 |
|
{7: 28 }line │rows: 5, cols: 24 |
|
||||||
{7: 29 }line │mouse enabled |
|
{7: 29 }line │mouse enabled |
|
||||||
{7: 30 }line │{1: } |
|
{7: 30 }line │{1: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
@@ -176,15 +177,49 @@ describe('terminal mouse', function()
|
|||||||
it('will lose focus if another window is clicked', function()
|
it('will lose focus if another window is clicked', function()
|
||||||
feed('<LeftMouse><5,1>')
|
feed('<LeftMouse><5,1>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 27 }line │line29 |
|
{7: 27 }line │line30 |
|
||||||
{7: 28 }l^ine │line30 |
|
{7: 28 }l^ine │rows: 5, cols: 25 |
|
||||||
{7: 29 }line │rows: 5, cols: 25 |
|
{7: 29 }line │rows: 5, cols: 24 |
|
||||||
{7: 30 }line │mouse enabled |
|
{7: 30 }line │mouse enabled |
|
||||||
{7: 31 } │{2: } |
|
{7: 31 } │{2: } |
|
||||||
========== ========== |
|
========== ========== |
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
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)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user