fig icon indicating copy to clipboard operation
fig copied to clipboard

Add a way to replace input with new command

Open clo4 opened this issue 3 years ago • 6 comments

The current solution to this is to prefix insertValue with as many \b as necessary, or to create a utility function that does this.

const replace = (cmd: string) => "\b".repeat(40) + cmd;

// ...
  subcommands: [
    {
      name: "My shortcut",
      insertValue: replace("cd ~/.fig/autocomplete; npm run dev\n")
    }
  ]

This is really easy to forget by accident. It could easily be handled by Fig, with something like a replaceCommand prop.

  subcommands: [
    {
      name: "My shortcut",
      replaceCommand: "cd ~/.fig/autocomplete; npm run dev\n"
    }
  ]

I think this should be lower priority than insertValue if they can't be exclusive. Order: insertValuereplaceCommandname

@fedeci @mschrage thoughts?

clo4 avatar Mar 01 '22 22:03 clo4

It doesn't sound bad to me! Let's wait for @mschrage feedback.

fedeci avatar Mar 04 '22 15:03 fedeci

Sorry I missed this. I like this API, if you want to add support for this @fedeci.

mschrage avatar Apr 08 '22 18:04 mschrage

I'm not sure if this is worth opening a separate issue but the \b shortcut seems to be ignored when used in template literals ``. Which even seems unofficially recognized in the docs https://fig.io/docs/guides/personal-shortcuts#create-some-shortcuts

joeyparis avatar Jul 12 '22 16:07 joeyparis

@joeyparis hmmm if \b is ignored then that's definitely a bug - JS treats it as an escape code for the backspace character (0x8). Could you open up a new issue and include your spec? I'll follow up there 🙂

clo4 avatar Jul 13 '22 04:07 clo4

@SeparateRecords absolutely!

joeyparis avatar Jul 13 '22 13:07 joeyparis

Related #1615, I'm pretty against adding a new property to autocomplete now that we have workflows.

fedeci avatar Jul 15 '22 12:07 fedeci

@fedeci replaceValue is necessary for functionality we want to enable for Mixins.

I was trying to make a mixin that runs a workflow. eg. I type "git" and it'll show a suggestion called "Create new feature branch", that just triggers a workflow

mschrage avatar Aug 26 '22 16:08 mschrage