Input in atom command


#1

I would like to make some commands that takes user inputs. I guess I will need to create some simple dialogue element. I looked at this link which may be related

But I must admit I don’t really understand what’s going on in the discussion, I’m quite new to coffee script as well as atom.
In my init file I have this command which is not working

atom.commands.add 'atom-text-editor', 'custom:cake', ->
  miniEditor = document.createElement('atom-text-editor')
  miniEditor.setAttribute('mini', true)

edit: 10+ if somebody could tell me how to format code (and thereby including tabs)
My best guess is that I need a command like “show” for the editor object, but again, I don’t know. Do you have a suggestion for a simple way to take inputs for a command, then I would appreciate it.


#2

There’s a </> button above the editor, but the best way is to “fence” with backticks, like so:

```coffeescript
atom.commands.add 'atom-text-editor', 'custom:cake', ->
  miniEditor = document.createElement('atom-text-editor')
  miniEditor.setAttribute('mini', true)
```

If you haven’t already, you should create a package using the built-in package generator (Packages -> Package Generator -> Generate Atom Package) so you can see how it works. Specifically, look at the function atom.workspace.addModalPanel(). That will accept your miniEditor as its item. You don’t have to have your code in a package, but it’s easier in some ways. init.coffee can get a little crowded.

You still have to learn how to actually submit the contents of the modal. A good example to look at is the package-generator code itself, specifically where the package binds the commands core:confirm and core:cancel to functions inside its own code, which define the actions for each command.


#3

There’s a </> button above the editor, but the best way is to “fence” with backticks, like so:

Thanks

If you haven’t already, you should create a package using the built-in package generator

For now i think ill manage with adding acommand, but ill look into packages when it becomes too fuzzy.

Specifically, look at the function atom.workspace.addModalPanel()

Okay so i made a class with an .item being a text editor. It basically looks like this

class ChocolateEditor
  constructor: () ->
    @disposables = new CompositeDisposable()
    @item = new TextEditor({mini: true})
    @element = document.createElement('div')
    @disposables.add( atom.commands.add( @element, {
      'core:cancel': () -> @close()
    }))

  close: () ->
    if !@panel.isVisible()
      return this.panel.hide()
    if (@previouslyFocusedElement != null)
      @previouslyFocusedElement.focus()

When calling cake, this does spawn a panel! However, close does not seem to work ( i guess it adds an instance to core:cancel which is bound to key escape?)