johnlindquist / kit

Script Kit. Automate Anything.
https://scriptkit.com
MIT License
3.91k stars 138 forks source link

`onEscape` can't work in editor API #1268

Closed youngkyo0504 closed 1 year ago

youngkyo0504 commented 1 year ago

https://github.com/johnlindquist/kit/assets/78121870/ec0d2404-3031-4120-a7c3-c6dcb44c8c69

This is my script code.

const main = async () => {
  const today = makeDateKey(new Date());
  const filePath = await getFilePath(today);
  let content = await ensureReadFile(filePath, createNewTemplate(today));
  const data = {content }
  editor({
      value: content,
      onInput: autoSave(filePath,data),
      onEscape:(e)=>{
        console.log('escape!!!!!')
        submit(data.content)
      },
    });
};

when I keydown ESCAPE, 'escape!!!!!' doesn't exist in log.

johnlindquist commented 1 year ago

@youngkyo0504

The escape shortcut will default to the "Back to Main Menu" behavior. CleanShot 2023-06-03 at 08 14 10

So you either need to:

Clear out the shortcuts

await editor({
  shortcuts: [],
  onEscape: () => {
    submit("test")
  },
})

Override the escape shortcut

let shortcuts = [
  {
    key: "escape",
    onPress: () => {
      submit("test")
    },
    name: "Submit Test",
    bar: "left",
  },
]

await editor({
  shortcuts,
})

Note: It's often preferable to override the shortcut so the user can see the name/action of the shortcut in the bottom bar.

youngkyo0504 commented 1 year ago

wow...! It works

thank you for answer my issue 👍