onivim / oni

Oni: Modern Modal Editing - powered by Neovim
https://www.onivim.io
MIT License
11.34k stars 299 forks source link

Binding <Enter> in Oni has various repercussions #2490

Open jwmann opened 6 years ago

jwmann commented 6 years ago

Oni Version: 0.3.6 Neovim Version (Linux only): Operating System: MacOS 10.13.5

Issue: Pressing Enter will work when in normal mode however when you try to do anything else while in normal mode, aka Cmd + P to find a file, pressing enter to select the file will trigger the binding and thus no longer select the file.

Expected behavior: The binding to work in relation to Vims and not while inside Oni's menus like Command Palette

Actual behavior: The Enter binding will trigger even inside Oni's menus. I need some way of excluding Oni's menus

Steps to reproduce:

  const isNormalMode = () => oni.editors.activeEditor.mode === "normal"

  oni.input.unbind("<enter>") // Not unbinding <enter> first will undo your last change every time you press it for some reason
  oni.input.bind("<enter>", "buffer.toggle", isNormalMode)
  1. Press C-P to being up the Command Palette
  2. Type a name to find a file
  3. Press Enter
oni-bot[bot] commented 6 years ago

Hello and welcome to the Oni repository! Thanks for opening your first issue here. To help us out, please make sure to include as much detail as possible - including screenshots and logs, if possible.

CrossR commented 6 years ago

I think this could be a more broad issue of how Oni deals with filters for bindings in a more user friendly way. (ie stuff like https://github.com/onivim/oni/issues/2194)

That is, its a bit confusing binding stuff and knowing what it will and won't affect. What it sounds like is that you want a "enter when in normal mode, but not when a menu is open". Which is totally possible, if you add a new filter like:

    const isMenuOpen = () => oni.menu.isMenuOpen()
    const isNormalMode = () => oni.editors.activeEditor.mode === "normal"

    oni.input.unbind("<enter>") // Not unbinding <enter> first will undo your last change every time you press it for some reason
    oni.input.bind("<enter>", "buffer.toggle", () => isNormalMode && !isMenuOpen)

...which is fine, but then enter doesn't work in the command line so you can't save that changed config. So you need to add an isCommandLine option too, and then at the end of all of it, you still don't really get anywhere since the initial unbind removed all the actions in menus and such. It gets very messy very quick since I was fixing one things and the next would break (QuickOpen, cmd mode, explorer, VCS bar etc)

I'm not sure if this is something you've thought about @bryphe but have you any ideas on how we can help this sort of issue? Its essentially a "I want to bind this here, but I don't want to change anything anywhere else mode". Or am I missing some option that would allow that to be easily achieved?

jwmann commented 6 years ago

I think you nailed it right on the head @CrossR

At least in Vim, you have the noremap option which helps with mapping conflicts.

I feel like Oni should have it's own "mode" which is flagged whenever we're interacting with an Oni element.

jwmann commented 6 years ago

I received an email about someone elses comment but I don't see it here for some reason.

hmmm... this is a pretty interesting case.

It could be solved by making a distinction if you are binding when focused on the editor pane or the general Oni layout, currently this is the cause for the issue. It seems that most keybindings should not have any effect when in temporary modals (e.g. Command Palette).

Other possibility, much more flexible but also more complex is to expose a command (e.g. oomap) that stores keybindings and strings (e.g. oomap , 'buffer.toggle'). This is very ad hoc though.

Just for the sake of curiosity, how do you insert line breaks and what's your use case?

To answer the last part, I insert line breaks while in insert mode using <CR> as per the default. I only have <CR> mapped for normal mode. If I want to insert line breaks without leaving normal mode, I use my Shift+k mapping like so:

    " Change the Shift+k function to something more useful: The opposite of doing Shift+j
    nnoremap K i<CR><Esc>^

the reason why I want to map enter is because simply faster to find buffers. I can do <CR>2<CR> in milliseconds, or <CR>mybuffername<CR> It's quite a nice way to find buffers. I do this in regular Vim albeit less fancy with this mapping:

  " Quick Find a Buffer
  nnoremap <CR> :ls<CR>:b<Space>

But the Oni vim buffer finder is much slicker and pleasant so I wanted to replace my current method with that.

badosu commented 6 years ago

I removed because it was a not well thought comment aftet re-reading the conversation again.

Em Qua, 15 de ago de 2018 13:30, James W Mann notifications@github.com escreveu:

I received an email about someone elses comment but I don't see it here for some reason.

hmmm... this is a pretty interesting case.

It could be solved by making a distinction if you are binding when focused on the editor pane or the general Oni layout, currently this is the cause for the issue. It seems that most keybindings should not have any effect when in temporary modals (e.g. Command Palette).

Other possibility, much more flexible but also more complex is to expose a command (e.g. oomap) that stores keybindings and strings (e.g. oomap , 'buffer.toggle'). This is very ad hoc though.

Just for the sake of curiosity, how do you insert line breaks and what's your use case?

To answer the last part, I insert line breaks while in insert mode using

as per the default. I only have mapped for normal mode. If I want to insert line breaks without leaving normal mode, I use my Shift+k mapping like so: " Change the Shift+k function to something more useful: The opposite of doing Shift+j nnoremap K i^ the reason why I want to map enter is because simply faster to find buffers. I can do 2 in milliseconds, or mybuffername It's quite a nice way to find buffers. I do this in regular Vim albeit less fancy with this mapping: " Quick Find a Buffer nnoremap :ls:b But the Oni vim buffer finder is much slicker and pleasant so I wanted to replace my current method with that. — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .
jwmann commented 6 years ago

Oh okay, my apologies, I still thought it was worth sharing since it sort've added to the conversation and also allowed me to explain the use case behind wanting to bind <enter>