]> git.r.bdr.sh - rbdr/dotfiles/blame - atom/packages/vim-mode/lib/view-models/vim-command-mode-input-element.coffee
Adds atom
[rbdr/dotfiles] / atom / packages / vim-mode / lib / view-models / vim-command-mode-input-element.coffee
CommitLineData
24c7594d
BB
1class VimCommandModeInputElement extends HTMLDivElement
2 createdCallback: ->
3 @className = "command-mode-input"
4
5 @editorContainer = document.createElement("div")
6 @editorContainer.className = "editor-container"
7
8 @appendChild(@editorContainer)
9
10 initialize: (@viewModel, opts = {}) ->
11 if opts.class?
12 @editorContainer.classList.add(opts.class)
13
14 if opts.hidden
15 @editorContainer.style.height = "0px"
16
17 @editorElement = document.createElement "atom-text-editor"
18 @editorElement.classList.add('editor')
19 @editorElement.getModel().setMini(true)
20 @editorElement.setAttribute('mini', '')
21 @editorContainer.appendChild(@editorElement)
22
23 @singleChar = opts.singleChar
24 @defaultText = opts.defaultText ? ''
25
26 @panel = atom.workspace.addBottomPanel(item: this, priority: 100)
27
28 @focus()
29 @handleEvents()
30
31 this
32
33 handleEvents: ->
34 if @singleChar?
35 @editorElement.getModel().getBuffer().onDidChange (e) =>
36 @confirm() if e.newText
37 else
38 atom.commands.add(@editorElement, 'editor:newline', @confirm.bind(this))
39
40 atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this))
41 atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this))
42 atom.commands.add(@editorElement, 'blur', @cancel.bind(this))
43
44 confirm: ->
45 @value = @editorElement.getModel().getText() or @defaultText
46 @viewModel.confirm(this)
47 @removePanel()
48
49 focus: ->
50 @editorElement.focus()
51
52 cancel: (e) ->
53 @viewModel.cancel(this)
54 @removePanel()
55
56 removePanel: ->
57 atom.workspace.getActivePane().activate()
58 @panel.destroy()
59
60module.exports =
61document.registerElement("vim-command-mode-input"
62 extends: "div",
63 prototype: VimCommandModeInputElement.prototype
64)