aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c4
-rw-r--r--src/nvim/buffer_defs.h3
-rw-r--r--src/nvim/ex_cmds.c4
-rw-r--r--src/nvim/move.c3
-rw-r--r--src/nvim/terminal.c7
-rw-r--r--src/nvim/ui.c4
-rw-r--r--src/nvim/window.c2
-rw-r--r--test/functional/terminal/mouse_spec.lua79
8 files changed, 76 insertions, 30 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index c15a6f1330..18706f0cbb 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -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);
+ }
}
/*
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 85043a2a35..076d1dfdc4 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -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 ====
*/
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index fe17314b8d..abdf411fc3 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -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--;
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 44ca10d11b..610fd04ebc 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -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;
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index e2e3bc5f30..6516f46b2f 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -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;
}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index ec0cfb6caa..b65f3be746 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -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);
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 36d780a661..0edb04f028 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -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));
}
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 263a5ce79d..5cd8c729cb 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -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)