dance icon indicating copy to clipboard operation
dance copied to clipboard

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

Open yyogo opened this issue 3 years ago • 10 comments

Due to https://github.com/microsoft/vscode/issues/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

yyogo avatar Dec 23 '21 10:12 yyogo

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.

wooden-worm avatar Jul 27 '22 01:07 wooden-worm

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

zetashift avatar Aug 11 '22 10:08 zetashift

@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

yyogo avatar Aug 11 '22 12:08 yyogo

Thank you!

zetashift avatar Aug 11 '22 16:08 zetashift

Added the config I'm using here

yyogo avatar Aug 14 '22 14:08 yyogo

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'"
  },

zetashift avatar Aug 14 '22 14:08 zetashift

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

wooden-worm avatar Sep 09 '22 01:09 wooden-worm

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.

71 avatar Sep 09 '22 10:09 71

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.

wooden-worm avatar Sep 09 '22 19:09 wooden-worm

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.

greneholt avatar Jun 30 '23 19:06 greneholt