Skip to content

Commit 05af9a4

Browse files
committed
patch 8.1.0015: cursor color wrong when closing a terminal window
Problem: Cursor color wrong when closing a terminal window, ending up in another terminal window. (Dominique Pelle) Solution: Bail out of terminal_loop() when the buffer changes. (closes #2942)
1 parent 6053f2d commit 05af9a4

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/terminal.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,25 @@ static int desired_cursor_blink = -1;
183183
* 1. Generic code for all systems.
184184
*/
185185

186-
static void
187-
cursor_color_copy(char_u** to_color, char_u* from_color)
188-
{
189-
vim_free(*to_color);
190-
*to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
191-
}
192-
193-
static int
186+
static int
194187
cursor_color_equal(char_u *lhs_color, char_u *rhs_color)
195188
{
196189
if (lhs_color != NULL && rhs_color != NULL)
197190
return STRCMP(lhs_color, rhs_color) == 0;
198191
return lhs_color == NULL && rhs_color == NULL;
199192
}
200193

201-
static char_u *
194+
static void
195+
cursor_color_copy(char_u **to_color, char_u *from_color)
196+
{
197+
// Avoid a free & alloc if the value is already right.
198+
if (cursor_color_equal(*to_color, from_color))
199+
return;
200+
vim_free(*to_color);
201+
*to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
202+
}
203+
204+
static char_u *
202205
cursor_color_get(char_u *color)
203206
{
204207
return (color == NULL) ? (char_u *)"" : color;
@@ -2119,15 +2122,15 @@ terminal_loop(int blocking)
21192122
while (must_redraw != 0)
21202123
if (update_screen(0) == FAIL)
21212124
break;
2122-
if (!term_use_loop_check(TRUE))
2125+
if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
21232126
/* job finished while redrawing */
21242127
break;
21252128

21262129
update_cursor(curbuf->b_term, FALSE);
21272130
restore_cursor = TRUE;
21282131

21292132
c = term_vgetc();
2130-
if (!term_use_loop_check(TRUE))
2133+
if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
21312134
{
21322135
/* Job finished while waiting for a character. Push back the
21332136
* received character. */
@@ -2178,7 +2181,8 @@ terminal_loop(int blocking)
21782181
#ifdef FEAT_CMDL_INFO
21792182
clear_showcmd();
21802183
#endif
2181-
if (!term_use_loop_check(TRUE))
2184+
if (!term_use_loop_check(TRUE)
2185+
|| in_terminal_loop != curbuf->b_term)
21822186
/* job finished while waiting for a character */
21832187
break;
21842188

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
15,
764766
/**/
765767
14,
766768
/**/

0 commit comments

Comments
 (0)