scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

Remapping alt+x to other character - new keyMap #129

Closed ultrox closed 5 years ago

ultrox commented 5 years ago

Thanks for your work on this wrapper, it saved me a lot of time, you most certainly need to provide donate button.

I'm trying to create new keymap for when a user click Alt+X(any character) to send something else.

This is my attempt with using extraKeys, which gets it triggerd but character I want doesn't get typed.

      extraKeys: {
        "Alt-A": cm => {
          console.log(cm, "a");
          return "F";
        },
        "Alt-S": cm => {
          console.log(cm, "s");
          return "K";
        }

I prepared minimal example on sandbox

I also read the documentation keymaps, but I was unable to find how to do this.

ultrox commented 5 years ago

Let me answer this one:

      extraKeys: {
        "Alt-A": cm => {
          console.log(cm, "a");
            cm.replaceSelection('G')
        },
        "Alt-S": cm => {
          console.log(cm, "s");
          cm.replaceSelection('Whatever')
        }