-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui)!: emit prompt "messages" as cmdline events #31525
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Hoping to make this incremental change while leaving what is displayed on the current message grid unaffected. Invoking a cmdline prompt affects the message grid globals however, which makes that tricky. Nearly there now but spending a lot of time trying to make it work; might have to leave this until after the message grid is hopefully removed... |
8ce796b
to
2a97fed
Compare
@@ -157,105 +147,60 @@ int get_keystroke(MultiQueue *events) | |||
return n; | |||
} | |||
|
|||
/// Get a number from the user. | |||
/// When "mouse_used" is not NULL allow using the mouse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR now also fixes mouse clicks for number prompts, which have been broken since 2019💀
commit 1ce28d7d9b2fd0e6a81174769e30dc59ded93876
Date: Sun Jun 9 16:00:09 2019 -0400
vim-patch:8.0.1756: GUI: after prompting for a number the mouse shape is wrong
The oldtests for this still passed because it bypasses the problem through nvim_input_mouse()
.
"Xtest-overwrite" | | ||
{9:WARNING: The file has been changed since reading it!!!} | | ||
{6:Do you really want to write to it (y/n)?}u | | ||
{6:Do you really want to write to it (y/n)?} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this test was to make sure no unprintable characters are put on the screen, which I suppose still holds true. The actual display difference seems insignificant.
src/nvim/ui.c
Outdated
@@ -721,7 +721,7 @@ void ui_call_event(char *name, bool fast, Array args) | |||
// Prompt messages should be shown immediately so must be safe | |||
if (strcmp(name, "msg_show") == 0) { | |||
char *kind = args.items[0].data.string.data; | |||
fast = !kind || ((strncmp(kind, "confirm", 7) != 0 && strstr(kind, "_prompt") == NULL)); | |||
fast = !kind || ((strncmp(kind, "confirm", 7) != 0 && strcmp(kind, "return_prompt") != 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably simplify this and remove the non-fast msg_show
path once all prompt messages are followed by a cmdline_show
event. Not sure it's worth the churn to move the "return_prompt" event there now (since it doesn't need to display user input). Probably best to leave that one alone and remove it altogether when we have a default UI that doesn't use it anymore. Heads up @folke.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me, it adds structure to flows that were spread around and implicit in various places.
It might be a bit risky but I think we should try it out.
@fredizzimo @glacambre @theol0403 do you see any obvious problems?
I haven't looked at the code, just did a quick check and this doesn't work too well with firenvim - |
I just rebased my default ext_ui branch on top of this (which I admittedly hadn't done yet, just looked at the affected ext_ui tests which seemed to show correct state). Seems to work as expected if you display the prompt message in the cmdline. |
9dd604e
to
aea19ad
Compare
I think this is dangerous. Any code can be executed in cmdline mode, so this can lead to potential segfaults, and defeat the point of #27874. |
It does matter. With a non-fast message the executed code is limited to the callback. With a cmdline prompt there can be autocommands from unrelated plugins. |
fyi, I'll be on vacation till January 1, so would be great not to merge this till I'm back, since this will break some things in noice, which are easy to fix, but will need to be fixed. ty |
Fine by me @folke. FYI (if we consider #31525 (comment) to be resolved); after this PR you would no longer have to keep track of an internal message queue for prompt messages, scheduled messages will be displayed when Nvim enters the cmdline state (@przepompownia). |
After several hours of working without a queue on this PR, I did not encounter any of the previously observed issues, especially with |
it seems to be no longer needed with neovim/neovim#31525
I tested this with Neovide, and didn't see any obvious problems, neither in practice nor when reviewing the code. So, this LGTM. |
]], | ||
} | ||
{3: }| | ||
|*2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small regression in this test simply because the message is now a cmdline prompt. This triggers a :set cmdheight=0
issue that happens somewhere in the incsearch path. Whenever cmdheight == 0 and we type /foo
, ?foo
or :%s/foo
where foo exceeds the number of Columns
we get a cmdline/msg_row
conflict, resulting in the cleared row and extra scrolled line here. I think it's related to:
Lines 237 to 240 in adcd936
// TODO(bfredl): this should already be the case, but fails in some | |
// "batched" executions where compute_cmdrow() use stale positions or | |
// something. | |
cmdline_row = msg_grid_pos; |
I could attempt to fix this but that work will be in vain assuming we remove the message grid after #27855 (and issue is not present with ext_cmdline (obviously)).
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will wait for @folke / Jan 2.
Needs a news item, perhaps in the "UI" section of news-features
. Or add a "UI" section to news-breaking.
I think it fits the "EVENTS" section in |
Problem: Prompts are emitted as messages events, where cmdline events are more appropriate. The user input is also emitted as message events in fast context, so cannot be displayed with vim.ui_attach(). Solution: Ask for user input through cmdline prompts.
@luukvbaal was just looking into fixing noice, but I'm seeing some weird behavior. I'm testing with: vim.fn.confirm("Save changes?", "&Yes\n&No\n&Cancel") When executing this:
I assume the Additionally, it also seems no longer possible to know that the |
It should, and that's precisely the behavior I'm seeing. I can try to reproduce with noice later.
I think you can use the |
Ok, thanks for confirming the behavior. Will see if I can create a repro without Noice. |
And yes, noice shows the prompt, which is fine, but knowing it's a prompt triggered by a confirm would be a nice to have, but not that important. |
Ok, figured it out. The vim.keymap.set("n", "T", function()
vim.fn.confirm("Save changes?", "&Yes\n&No\n&Cancel")
end, { silent = true }) |
After further testing, the behavior without With my example, and without using a keymap and with
|
Yeah I meant the same broken behavior. That is a regression that should be fixed. |
Problem: Prompts are emitted as message events, where cmdline events
are more appropriate. The user input is also emitted as
message events in fast context, so cannot be displayed with
vim.ui_attach().
Solution: Ask for user input through cmdline prompts.