feat(ex_cmds): :sleep! hides the cursor while sleeping (#31493)

Problem:  :sleep! not hiding the cursor is an arbitrary difference from
          Vim without obvious justification, and Vim's behavior isn't
          easily achievable in Nvim.
Solution: Make :sleep! hide the cursor while sleeping.

Ref:
6a01b3fcc3
b5c0ade437
This commit is contained in:
zeertzjq 2024-12-07 21:42:44 +08:00 committed by GitHub
parent 92e61072ac
commit 4817547ec4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 4 deletions

View File

@ -1569,6 +1569,8 @@ tag command action ~
|:sign| :sig[n] manipulate signs |:sign| :sig[n] manipulate signs
|:silent| :sil[ent] run a command silently |:silent| :sil[ent] run a command silently
|:sleep| :sl[eep] do nothing for a few seconds |:sleep| :sl[eep] do nothing for a few seconds
|:sleep!| :sl[eep]! do nothing for a few seconds, without the
cursor visible
|:slast| :sla[st] split window and go to last file in the |:slast| :sla[st] split window and go to last file in the
argument list argument list
|:smagic| :sm[agic] :substitute with 'magic' |:smagic| :sm[agic] :substitute with 'magic'

View File

@ -552,8 +552,7 @@ gO Show a filetype-specific, navigable "outline" of the
Queued messages are processed during the sleep. Queued messages are processed during the sleep.
*:sl!* *:sleep!* *:sl!* *:sleep!*
:[N]sl[eep]! [N][m] Same as above. Unlike Vim, it does not hide the :[N]sl[eep]! [N][m] Same as above, but hide the cursor.
cursor. |vim-differences|
============================================================================== ==============================================================================
2. Using Vim like less or more *less* 2. Using Vim like less or more *less*

View File

@ -670,7 +670,6 @@ Commands:
- :promptrepl - :promptrepl
- :scriptversion (always version 1) - :scriptversion (always version 1)
- :shell - :shell
- :sleep! (does not hide the cursor; same as :sleep)
- :smile - :smile
- :tearoff - :tearoff
- :cstag - :cstag

View File

@ -6101,7 +6101,9 @@ static void ex_sleep(exarg_T *eap)
default: default:
semsg(_(e_invarg2), eap->arg); return; semsg(_(e_invarg2), eap->arg); return;
} }
do_sleep(len, false);
// Hide the cursor if invoked with !
do_sleep(len, eap->forceit);
} }
/// Sleep for "msec" milliseconds, but return early on CTRL-C. /// Sleep for "msec" milliseconds, but return early on CTRL-C.

View File

@ -361,4 +361,38 @@ describe('ui/cursor', function()
end end
end) end)
end) end)
it(':sleep does not hide cursor when sleeping', function()
n.feed(':sleep 100m | echo 42\n')
screen:expect({
grid = [[
^ |
{1:~ }|*3
:sleep 100m | echo 42 |
]],
timeout = 100,
})
screen:expect([[
^ |
{1:~ }|*3
42 |
]])
end)
it(':sleep! hides cursor when sleeping', function()
n.feed(':sleep! 100m | echo 42\n')
screen:expect({
grid = [[
|
{1:~ }|*3
:sleep! 100m | echo 42 |
]],
timeout = 100,
})
screen:expect([[
^ |
{1:~ }|*3
42 |
]])
end)
end) end)