onivim / oni

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

Keybinding Mechanism isn't Robust #1240

Open saibing opened 6 years ago

saibing commented 6 years ago
const activate = (oni) => {
    console.log("config activated")

    // Input 
    //
    // Add input bindings here:
    //
    oni.input.bind("<c-enter>", () => console.log("Control+Enter was pressed"))
    oni.input.bind("<c-s-r>", "language.findAllReferences")

    //
    // Or remove the default bindings here by uncommenting the below line:
    //
    // oni.input.unbind("<c-p>")
}

I input <c-enter> , there is no any output on developer console I input <c-s-r>, there is no any response.

mchalkley commented 6 years ago

The way I'm doing this now, per a suggestion from the gittr discussion page, is in the Oni\resources\app\vim\core\oni-core-interop\plugin\init.vim file, using the normal vim remap commands...

You may also need add a line into your config.js file (via File>Preferences) to tell Oni not to use its default config, as shown below:

const activate = (oni) => { // access the Oni plugin API here

// for example, unbind the default <c-p> action: // oni.input.unbind("")

// or bind a new action:

//oni.input.bind("", "oni.quit") };

module.exports = { activate, // change configuration values here: "oni.useDefaultConfig": false //"oni.loadInitVim": true, //"editor.fontSize": "14px", //"editor.fontFamily": "Monaco", //"editor.completions.enabled": true }

I hope this helps...

Mark

CrossR commented 6 years ago

Other thing to check is that you have activate being called in your module.export, ie


module.exports = {
    activate,
    ...
}
saibing commented 6 years ago

@mchalkley Thank you. It works well.

@CrossR Thank you for your reminder

I have already call activate in config.js because that 'config activated' message has been output to the console, but the shortcut key does not work.

const activate = (oni) => {
    console.log("config activated")

    // Input 
    //
    // Add input bindings here:
    //
    //oni.input.bind("<c-enter>", () => console.log("Control+Enter was pressed"))
    oni.input.bind("<c-s-r>", "language.findAllReferences")

    //
    // Or remove the default bindings here by uncommenting the below line:
    //
    // oni.input.unbind("<c-p>")
}

const deactivate = () => {
    console.log("config deactivated")
}

module.exports = {
    activate,
    deactivate,
    //add custom config here, such as
    //"oni.useDefaultConfig": true,
    //"oni.bookmarks": ["~/Documents",]
saibing commented 6 years ago

@bryphe Could you add a defualt sortcut key for language.findAllReferences command.

It is not included in the shortcuts list.

CrossR commented 6 years ago

@saibing, I took another look and realised you were also calling the wrong command, it should be oni.editor.findAllReferences.

    oni.input.bind("<s-c-r>", "oni.editor.findAllReferences")

works for me, so hopefully should work for you. May require you to restart Oni after updating your config.js.

That said, it also looks like Oni is currently treating keybinds with modifiers in a specific order.

When I tried c-s-r it failed to work, but s-c-r did work. The debug log shows that the keyboard output is s-c-r but really they are the exact same thing. This was tested with unbind as well, and that didn't seem to help.

Maybe a PR is needed such that on parsing a keybind we treat modifiers differently, and sort them? Though then we could get ourselves into more awkward situations if we need to start doing that.

saibing commented 6 years ago

@CrossR

Thank you very much:)

oni.input.bind("<s-c-r>", "language.findAllReferences")

The above bind also works well. The command "language.findAllReferences" is the same as "oni.editor.findAllReferences"

You are right that the problem is <c-s-r> does not work.

bryphe commented 6 years ago

Nice find @CrossR on the issue!

That input issue seems like a bug to me - It would be nice if our input handling was more robust and recognized both <c-s-r> and <s-c-r> - I think the former is more common anyway.

So I'll leave this open to track a couple of fixes: