ex-mode/lib/ex-normal-mode-input-element.coffee
jazzpi 42a44ee9e1 Add specs; minor changes to some commands
`:tabedit` now works as an alias to `:edit` with a path and
  as an alias to `:tabnew` without.
`:tabnew` is a new command that opens a new tab with a new file if used
 without a path and works as an alias to `:tabedit` with one.
`:tabclose` now works as a proper alias to `:quit` (i.e. passes the arguments)
`:edit` now works more like before - it opens a given path in a new tab.
 It also doesn't do anything if the file was modified since the last commit,
 unless forced by using `:edit!`
`:write` works properly again and doesn't overwrite files, unless forced by
 using `:write!`
`:xit` is now called `:xit` and not just `:x`
`:substitute` now properly replaces multiple groups (`:s/(a)b(c)/X\1\2X\0`)
2015-07-29 19:13:13 +02:00

64 lines
1.7 KiB
CoffeeScript

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
)