comply with new Atom API
This commit is contained in:
parent
1c064ec13a
commit
3f75ca3a30
6 changed files with 74 additions and 69 deletions
64
lib/ex-command-mode-input-element.coffee
Normal file
64
lib/ex-command-mode-input-element.coffee
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
class ExCommandModeInputElement extends HTMLDivElement
|
||||
createdCallback: ->
|
||||
@className = "command-mode-input"
|
||||
|
||||
@editorContainer = document.createElement("div")
|
||||
@editorContainer.className = "editor-container"
|
||||
|
||||
@appendChild(@editorContainer)
|
||||
|
||||
initialize: (@viewModel, opts = {}) ->
|
||||
if opts.class?
|
||||
@editorContainer.classList.add(opts.class)
|
||||
|
||||
if opts.hidden
|
||||
@editorContainer.style.height = "0px"
|
||||
|
||||
@editorElement = document.createElement "atom-text-editor"
|
||||
@editorElement.classList.add('editor')
|
||||
@editorElement.getModel().setMini(true)
|
||||
@editorElement.setAttribute('mini', '')
|
||||
@editorContainer.appendChild(@editorElement)
|
||||
|
||||
@singleChar = opts.singleChar
|
||||
@defaultText = opts.defaultText ? ''
|
||||
|
||||
@panel = atom.workspace.addBottomPanel(item: this, priority: 100)
|
||||
|
||||
@focus()
|
||||
@handleEvents()
|
||||
|
||||
this
|
||||
|
||||
handleEvents: ->
|
||||
if @singleChar?
|
||||
@editorElement.getModel().getBuffer().onDidChange (e) =>
|
||||
@confirm() if e.newText
|
||||
else
|
||||
atom.commands.add(@editorElement, 'editor:newline', @confirm.bind(this))
|
||||
|
||||
atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this))
|
||||
atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this))
|
||||
atom.commands.add(@editorElement, 'blur', @cancel.bind(this))
|
||||
|
||||
confirm: ->
|
||||
@value = @editorElement.getModel().getText() or @defaultText
|
||||
@viewModel.confirm(this)
|
||||
@removePanel()
|
||||
|
||||
focus: ->
|
||||
@editorElement.focus()
|
||||
|
||||
cancel: (e) ->
|
||||
@viewModel.cancel(this)
|
||||
@removePanel()
|
||||
|
||||
removePanel: ->
|
||||
atom.workspace.getActivePane().activate()
|
||||
@panel.destroy()
|
||||
|
||||
module.exports =
|
||||
document.registerElement("ex-command-mode-input"
|
||||
extends: "div",
|
||||
prototype: ExCommandModeInputElement.prototype
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue