71 / dance

Make your cursors dance with Kakoune-like modal editing in VS Code.
https://marketplace.visualstudio.com/items?itemName=gregoire.dance
ISC License
437 stars 55 forks source link

`ifEmpty` does not pass count to it's subcommands. #310

Closed haberdashPI closed 1 year ago

haberdashPI commented 1 year ago

While debugging #308 I discovered that for all cases I tried, the count entered by a user is not passed on to the subcommands called in "then" or "otherwise" of an "ifEmpty" command.

I'm happy to try to resolve this but I am having a but of trouble following the data flow for how counts get passed around. Looking at the source for buildCommands it appears that the count is only passed down to individual commands if it is an explicit argument. Is this just so one can specify a command with an explicit numerical argument, or is there some way to spell out, in a call to ifEmpty that you want the count to be passed to one of the subcommands. If so, how does one do that, and is that documented somewhere? (I can't seem to find it).

71 commented 1 year ago

This probably needs some better documentation, but you can use the $include and $exclude arguments for that:

  {
    "key": ",",
    "command": "dance.ifEmpty",
    "when": "editorTextFocus && dance.mode == 'normal'",
    "args": {
      "then": [["dance.select.down.extend", { "$include": ["count"] }]],
      "otherwise": [["dance.select.up.extend", { "$include": ["count"] }]],
    },
  },

or:

  {
    "key": ",",
    "command": "dance.ifEmpty",
    "when": "editorTextFocus && dance.mode == 'normal'",
    "args": {
      "then": [["dance.select.down.extend", { "$exclude": [] }]],
      "otherwise": [["dance.select.up.extend", { "$exclude": [] }]],
    },
  },

Note regarding your PR: when you write ... in the arguments of a command (example), this is expanded to "$exclude": [], i.e. other arguments are passed to the command.