Skip to content

Conversation

@matveyt
Copy link
Contributor

@matveyt matveyt commented Jul 8, 2022

Closes #15521

@github-actions github-actions bot added the defaults Nvim defaults for options, colorscheme/theme, autocmds/events, etc. label Jul 8, 2022
@justinmk
Copy link
Member

justinmk commented Jul 8, 2022

Can't do this until the full suggestion in #15521 (comment) is implemented.

  1. We need a right-click menu that has things like:
    Copy
    Cut
    Paste
    Disable mouse
    
  2. we need alt+click to temporarily set mouse= until the next cursor-move. this is an escape-hatch to allow copying screen elements that otherwise aren't copyable

@matveyt
Copy link
Contributor Author

matveyt commented Jul 8, 2022

Can't do this until the full suggestion in #15521 (comment) is implemented.

As menu functionality has been implemented, do I understand right that we lack few default commands, such as :menu PopUp.Paste "+gP, plus new help topic?

@justinmk
Copy link
Member

justinmk commented Jul 9, 2022

As menu functionality has been implemented, do I understand right that we lack few default commands, such as :menu PopUp.Paste "+gP, plus new help topic?

correct

@matveyt
Copy link
Contributor Author

matveyt commented Jul 10, 2022

@justinmk All done. The menu is embedded into C code to match with default mappings and autocommands.

I also changed the default for set mousemodel=popup_setpos to enable the menu from startup. But now it looks like a problem with functional tests, in particular, this one.

AFAIU, the test emulates mouse clicks in the status line area, but the popup menu shows up unexpectedly. So what's the plan? To reset mousemodel to "extend", or to set it for this test specifically, or to patch popup menu implementation, so it doesn't show up upon a click outside of buffer area?

Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking quite good, thanks for putting some thought into this :)

@justinmk

This comment was marked as resolved.

@famiu
Copy link
Member

famiu commented Jul 14, 2022

But now it looks like a problem with functional tests, in particular, this one.
AFAIU, the test emulates mouse clicks in the status line area, but the popup menu shows up unexpectedly. So what's the plan? To reset mousemodel to "extend", or to set it for this test specifically, or to patch popup menu implementation, so it doesn't show up upon a click outside of buffer area?

@famiu does your PR help here? #19252

It should, yeah

@matveyt
Copy link
Contributor Author

matveyt commented Jul 14, 2022

@justinmk Okay, no problem. Should we also merge default autocmds in? Kind of init_default_actions() for everything, except the options?

could instead be done in Lua

I see neither l10n nor menu API but that's not important, I guess. Just going to embed a piece of VimScript into Lua for now.

@justinmk
Copy link
Member

justinmk commented Jul 14, 2022

Should we also merge default autocmds in? Kind of init_default_actions() for everything, except the options?

no, don't want to decide that right now :)

Menus really are just mappings. So init_default_mappings does not need to be renamed.

Just going to embed a piece of VimScript into Lua for now.

that's fine--thanks!

@matveyt
Copy link
Contributor Author

matveyt commented Jul 15, 2022

Moved default mappings and menus to Lua. Cleaned up C code.

The functional test fails until PR #19252 merged.

Conflicts with PR #19365 as init_default_mappings() is about to be removed from mapping.c. So need to port the new mapping to Lua when accepted.

@matveyt matveyt requested a review from justinmk July 15, 2022 11:27
anoremenu PopUp.Paste "+gP
vnoremenu PopUp.Paste "+p
vnoremenu PopUp.Delete "_x
nnoremenu PopUp.Select\ All ggVG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo(?): for many of these, it might be nice to maintain the cursor position and the viewport, so there is no visible jumping-around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for "Select All" and other Visual-related stuff, it's impossible, AFAIU. The editor really wants to keep the cursor both visible and anchored to one of selection ends, so it may adjust the selected range upon any viewport change.

@justinmk
Copy link
Member

justinmk commented Jul 15, 2022

  • merged fix: right click in clickable statusline #19252 , try rebasing ?
  • let's drop the "Undo" menu item for now; it raises the question "what about Redo?", and also doesn't seem valuable enough, especially as the first item.
  • do we want a Go to definition item that maps to ctrl-] ?
    • would probably want to use <Cmd>lua vim.lsp.buf.definition()<CR> if #vim.lsp.get_active_clients({bufnr=vim.api.nvim_get_current_buf()}) > 0

Future

  1. Enabling mouse opens the door to adding clickable sections to the default 'statusline' and 'tabline'.
    • most important function here would be to expose the message / notification history somehow

@matveyt
Copy link
Contributor Author

matveyt commented Jul 16, 2022

  1. Rebasing done; test "startup_spec" fixed; "undo" item removed; Visual Paste changed from "p" to "P".

  2. The test "statusline_spec" is falling again. But it only complains that it failed to require "vim.shared". And I can't figure why so?!

  3. "Go to definition" item currently may look like this:

anoremenu PopUp.Go\ to\ definition      <Cmd>lua
  \ if #vim.lsp.get_active_clients() > 0 then
  \   vim.lsp.buf.definition()
  \ else
  \   vim.cmd 'normal! <C-]>'
  \ end<CR>
vnoremenu PopUp.Go\ to\ definition      <Cmd>lua
  \ if #vim.lsp.get_active_clients() > 0 then
  \   vim.lsp.buf.definition()
  \ else
  \   vim.cmd 'normal! <C-]>'
  \ end<CR>

It's working but looks ugly, so I didn't add it yet. BTW. "vnoremenu" with the same code needed, because "amenu" would drop from Visual mode, and so it ignored the selected text in favor of the word under cursor.

  1. Considering this and also a "save view" capability, I thought that we might need some new helper for that. Perhaps, something like this
---@param expr          Lua function or string of "normals"
---@param opts          Table with optional keys:
---                               args - array of args for expr
---                               cond, fallback - some condition and "fallback" action
---                               keepview, remap - some boolean flags
---                               more stuff maybe...
function vim.action(expr, opts)
...
end

Then the menu items could look like this <Cmd>lua vim.action(vim.lsp.buf.definition, { cond = #vim.lsp.get_active_clients() > 0, fallback = '<C-]>' })<CR>. Or maybe <Cmd>lua vim.action(vim.api.nvim_put, { args = {...}, keepview = true } )<CR>, and so on.

But this one could also become redundant if menu API is ever ported to Lua.

  1. I was also thinking about new <Lua> token for mappings. Sort of
<Lua>
    print"Hello world"
<CR>

which is a rough equivalent of

<Cmd>lua << <CR>
    print"Hello world"
<CR>

except the latter is not working, of course. But this probably deserves opening a new issue first. And again, it's more useful for mappings defined in VimScript. With nvim_set_keymap() and friends floating around it may be considered obsolete from the very beginning.

@justinmk
Copy link
Member

do we need a aunmenu in test/functional/ui/statusline_spec.lua ?

RUN      T4735 statusline clicks works: -- Tests exited non-zero: Process terminated due to timeout

@justinmk
Copy link
Member

windows CI failure is unrelated, known flakey test:

  ERROR    test/functional\vimscript\let_spec.lua @ 28: :let :unlet self-referencing node in a List graph #6070
  test\functional\helpers.lua:106: EOF was received from Nvim. Likely the Nvim process crashed.

@matveyt

This comment was marked as resolved.

@justinmk justinmk merged commit eb9b93b into neovim:master Jul 17, 2022
@neovim neovim locked as resolved and limited conversation to collaborators Jul 17, 2022
@gpanders
Copy link
Member

  • would probably want to use <Cmd>lua vim.lsp.buf.definition()<CR> if #vim.lsp.get_active_clients({bufnr=vim.api.nvim_get_current_buf()}) > 0

'tagfunc' is set by default in LSP buffers now, so we may not need this special case.

@justinmk
Copy link
Member

justinmk commented Jul 17, 2022

Resolution

  • Oceania has always been at war with Eastasia. Nvim has always enabled 'mouse' by default.
  • defaults: Revert 'mouse=a' #6022 temporarily disabled 'mouse' with the intention of re-enabling it after we had a full answer for users who were used to the old behavior.
  • The full answer is now provided by this PR, specifically:
    • :set mouse=nvi
    • Pressing ":" (to enter cmdline-mode) temporarily disables mouse. Try it.
    • Right-click shows a popup menu with: Cut, Copy, Paste, Disable mouse
      • The Disable mouse item shows :help default-mouse which explains how to disable mouse permanently.

Future

  1. Do we want a Go to definition item that maps to ctrl-] ?
    • Also works for LSP because vim.lsp sets 'tagfunc' by default.
  2. Enabling mouse opens the door to adding clickable sections to the default 'statusline' and 'tabline'.
    • most important function here would be to expose the message / notification history somehow

Locked to keep the summary visible. You can always chat or open an issue if you have new information/topics to discuss.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

defaults Nvim defaults for options, colorscheme/theme, autocmds/events, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defaults: enable mouse support

5 participants