glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.65k stars 143 forks source link

[Feature Request] Ignore all key combinations involving a modifier without specifying them explicitly #1527

Closed MahdiNazemi closed 1 year ago

MahdiNazemi commented 1 year ago

What I tried to do

Ignore all key combinations that involve the CMD key, i.e., <D->, <SD->, <SAD->, and <SACD->.

What happened

Based on README.md, I suspect I have to specify all possible combinations explicitly (under ignoreKeys), but I assume there is an easier way to use a wildcard to specify all possible combinations.

glacambre commented 1 year ago

Would adding something like

for MOD in ['', 'A', 'S', 'C']
  for KEY in "abcdefghijklmnopqrstuvwxyz"
    call execute("nnoremap <D" .. MOD .. "-" .. KEY .. "> <nop>")
  endfor
endfor

To your init.vim do what you want it to do?

MahdiNazemi commented 1 year ago

I added the nested loop you shared to my configurations, but the key combinations were not ignored. For example, pressing CMDS did not open the save dialog.

I also modified my question to be more clear that I like these key combinations to be ignored (ignoreKeys).

alerque commented 1 year ago

Mapping the keys to a <nop> in NeoVIM won't change the fact that the key is getting passed to Firenvim in the first place. It sounds like you are trying to get those keys handled by the browser outside of Firenvim, no?

glacambre commented 1 year ago

I also modified my question to be more clear that I like these key combinations to be ignored (ignoreKeys).

Ah, right, the solution I provided wouldn't work for this. This one should though:

let ignorekeys = []
for MOD in ['', 'A', 'S', 'C']
  for KEY in "abcdefghijklmnopqrstuvwxyz"
    let ignorekeys += ["<D" .. MOD .. "-" .. KEY .. ">"]
  endfor
endfor
let g:firenvim_config = {
    \ 'globalSettings': {
        \ 'ignoreKeys': {
            \ 'all': ignorekeys
        \ }
    \ }
\}

Note that this doesn't actually ignore all of the bindings you mentionned (e.g. <SACD->), but nesting for loops or a bit of smarter programming should be able to do that :)

MahdiNazemi commented 1 year ago

Thank you! Based on your code, I wrote something that is not as clean but gets the job done:

let ignorekeys = []
for KEY in "abcdefghijklmnopqrstuvwxyz0123456789"
  let ignorekeys += ["<D-" .. KEY .. ">"]
  let ignorekeys += ["<SD-" .. KEY .. ">"]
  let ignorekeys += ["<SAD-" .. KEY .. ">"]
  let ignorekeys += ["<SACD-" .. KEY .. ">"]
endfor

I added digits 0-9 to KEYs to allow switching tabs with e.g. CMD1.

MahdiNazemi commented 1 year ago

Mapping the keys to a <nop> in NeoVIM won't change the fact that the key is getting passed to Firenvim in the first place. It sounds like you are trying to get those keys handled by the browser outside of Firenvim, no?

You are right. I should have explained that more clearly in the description of the issue.