Skip to content

Commit

Permalink
patch 8.2.2754: :sleep! does not always hide the cursor
Browse files Browse the repository at this point in the history
Problem:    :sleep! does not always hide the cursor.
Solution:   Add the cursor_is_asleep flag. (Jeremy Lerner, closes vim#8097,
            closes vim#7998)
  • Loading branch information
brammool committed Apr 11, 2021
1 parent f93bbd0 commit 09f067f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/drawscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ update_screen(int type_arg)
// Remove the cursor before starting to do anything, because
// scrolling may make it difficult to redraw the text under
// it.
if (gui.in_use && wp == curwin)
// Also remove the cursor if it needs to be hidden due to an
// ongoing cursor-less sleep.
if (gui.in_use && (wp == curwin || cursor_is_sleeping()))
{
gui_cursor_col = gui.cursor_col;
gui_cursor_row = gui.cursor_row;
Expand All @@ -306,7 +308,6 @@ update_screen(int type_arg)
}
}
#endif

win_update(wp);
}

Expand Down
5 changes: 4 additions & 1 deletion src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7370,7 +7370,7 @@ do_sleep(long msec, int hide_cursor)
# endif

if (hide_cursor)
cursor_off();
cursor_sleep();
else
cursor_on();

Expand Down Expand Up @@ -7422,6 +7422,9 @@ do_sleep(long msec, int hide_cursor)
// input buffer, otherwise a following call to input() fails.
if (got_int)
(void)vpeekc();

if (hide_cursor)
cursor_unsleep();
}

/*
Expand Down
5 changes: 5 additions & 0 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,11 @@ gui_update_cursor(
|| gui.row != gui.cursor_row || gui.col != gui.cursor_col)
{
gui_undraw_cursor();

// If a cursor-less sleep is ongoing, leave the cursor invisible
if (cursor_is_sleeping())
return;

if (gui.row < 0)
return;
#ifdef HAVE_INPUT_METHOD
Expand Down
3 changes: 3 additions & 0 deletions src/proto/term.pro
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void scroll_start(void);
void cursor_on_force(void);
void cursor_on(void);
void cursor_off(void);
int cursor_is_sleeping(void);
void cursor_sleep(void);
void cursor_unsleep(void);
void term_cursor_mode(int forced);
void term_cursor_color(char_u *color);
int blink_state_is_inverted(void);
Expand Down
36 changes: 35 additions & 1 deletion src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -3932,8 +3932,12 @@ scroll_start(void)
}
}

// True if cursor is not visible
static int cursor_is_off = FALSE;

// True if cursor is not visible due to an ongoing cursor-less sleep
static int cursor_is_asleep = FALSE;

/*
* Enable the cursor without checking if it's already enabled.
*/
Expand All @@ -3942,6 +3946,7 @@ cursor_on_force(void)
{
out_str(T_VE);
cursor_is_off = FALSE;
cursor_is_asleep = FALSE;
}

/*
Expand All @@ -3950,7 +3955,7 @@ cursor_on_force(void)
void
cursor_on(void)
{
if (cursor_is_off)
if (cursor_is_off && !cursor_is_asleep)
cursor_on_force();
}

Expand All @@ -3967,6 +3972,35 @@ cursor_off(void)
}
}

/*
* Check whether the cursor is invisible due to an ongoing cursor-less sleep
*/
int
cursor_is_sleeping(void)
{
return cursor_is_asleep;
}

/*
* Disable the cursor and mark it disabled by cursor-less sleep
*/
void
cursor_sleep(void)
{
cursor_is_asleep = TRUE;
cursor_off();
}

/*
* Enable the cursor and mark it not disabled by cursor-less sleep
*/
void
cursor_unsleep(void)
{
cursor_is_asleep = FALSE;
cursor_on();
}

#if defined(CURSOR_SHAPE) || defined(PROTO)
/*
* Set cursor shape to match Insert or Replace mode.
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2754,
/**/
2753,
/**/
Expand Down

0 comments on commit 09f067f

Please sign in to comment.