71/dance

Default key binding for "dance.seek.askObject.inner" (alt+i) doesn't work on MacOS

Opened this issue · 10 comments

yyogo commented

Due to microsoft/vscode#41024, this key combination cannot be mapped on MacOS (as well as alt+`,e,n,u and possibly others)

I've remapped it to ctrl+i but I think the defaults should also be adjusted

I'm having the same issue and had to change the input source to Unicode Hex Input for the shortcut to work.

I think dance can steal the match mode from helix: https://docs.helix-editor.com/keymap.html#match-mode

Essentially in helix you press m to enter its Match mode, which you can then follow by i to get into Match inner. So instead of Alt + i you press mi. Match mode shows a menu of possible options, so way easier to discover.

Is there a way/example to configure Dance to use those helix type of keybindings? E.g. mi" for match inner quotation marks?

yyogo commented

@zetashift you could remap m i to dance.seek.askObject.inner e.g:

    {
        "key": "m i",
        "command": "dance.seek.askObject.inner",
        "when": "editorTextFocus && dance.mode == 'normal'"
    },

A more advanced approach would be to map m to a custom menu, see e.g https://github.com/71/dance/wiki/Mirror-menu

Thank you!

yyogo commented

Added the config I'm using here

Oh that's very nice, here is mine:

  "key": "m",
    "command": "dance.openMenu",
    "args": {
      "menu": {
        "items": {
          "i": {
            "text": "select inner object",
            "command": "dance.seek.askObject.inner"
          },
          "a": {
            "text": "select object",
            "command": "dance.seek.askObject"
          },
          "s": {
            "text": "surround around object",
            "command": "dance.openMenu",
            "args": {
              "menu": {
                "items": {
                  "(": {
                    "text": "(surround)",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '(' + x + ')')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "(" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": ")" }
                        ]
                      ]
                    }
                  },
                  "{": {
                    "text": "{surround}",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '{' + x + '}')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "{" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": "}" }
                        ]
                      ]
                    }
                  },
                  "[": {
                    "text": "[surround]",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '[' + x + ']')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "[" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": "]" }
                        ]
                      ]
                    }
                  },
                  "<": {
                    "text": "<surround>",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '<' + x + '>')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "<" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": ">" }
                        ]
                      ]
                    }
                  },
                  "\"": {
                    "text": "\"surround\"",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '\"' + x + '\"')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "\"" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": "\"" }
                        ]
                      ]
                    }
                  },
                  "'": {
                    "text": "'surround'",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => `'` + x + `'`)",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "'" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": "'" }
                        ]
                      ]
                    }
                  },
                  "`": {
                    "text": "`surround`",
                    "command": "dance.run",
                    "args": {
                      "input": "await replace((x) => '`' + x + '`')",
                      "commands": [
                        [
                          ".edit.insert",
                          { "where": "start", "shift": "extend", "text": "`" }
                        ],
                        [
                          ".edit.insert",
                          { "where": "end", "shift": "extend", "text": "`" }
                        ]
                      ]
                    }
                  }
                }
              }
            }
          },
          "d": {
            "text": "delete surround",
            "command": "dance.run",
            "args": {
              "input": "await replace((x) => x.slice(1, -1))",
              "commands": [
                ".selections.save",
                ".selections.reduce.edges",
                ".edit.delete",
                ".selections.restore"
              ]
            }
          }
        }
      }
    },
    "when": "editorTextFocus && dance.mode == 'normal'"
  },

m conflicts with the default match command. @71 would you consider something similar to what @zetashift posted above?

71 commented

For now the default keybindings are Kakoune's on Windows and Linux (though I'd like to change this), so I think we should keep the current command. The wiki is where we can put custom keybindings in the meantime.

Sorry bad phrasing on my part. I meant would you consider adding a "match menu", which cover seek.Object commands https://github.com/71/dance/tree/master/src/commands#seekobject and probably surround add/delete as posted above? Of course with a different key than m since it's used.

It's just not a custom key binding but a new menu/feature.

This StackOverflow answer explains how to completely prevent Option+key from producing special characters on Mac, allowing you to use these combinations for shortcuts in VS Code and various other editors.

In short:

  1. Download this QWERTY keyboard layout file (or generate one yourself using the instructions in the linked answer).
  2. Move it to ~/Library/Keyboard Layouts/
  3. Go to System Settings > Keyboard > Text Input > Input Sources > Edit.
  4. Click + in the bottom left, scroll to the bottom of the list on the left and select Others then select QWERTY no option and click Add.
  5. Either delete your existing layout (probably called U.S.) or just switch to the QWERTY no option layout using the input-source select in the menu bar.