]>
Commit | Line | Data |
---|---|---|
455f099b | 1 | class VimNormalModeInputElement extends HTMLDivElement |
24c7594d | 2 | createdCallback: -> |
455f099b | 3 | @className = "normal-mode-input" |
24c7594d | 4 | |
455f099b | 5 | initialize: (@viewModel, @mainEditorElement, opts = {}) -> |
24c7594d | 6 | if opts.class? |
455f099b | 7 | @classList.add(opts.class) |
24c7594d BB |
8 | |
9 | @editorElement = document.createElement "atom-text-editor" | |
10 | @editorElement.classList.add('editor') | |
11 | @editorElement.getModel().setMini(true) | |
12 | @editorElement.setAttribute('mini', '') | |
455f099b | 13 | @appendChild(@editorElement) |
24c7594d BB |
14 | |
15 | @singleChar = opts.singleChar | |
16 | @defaultText = opts.defaultText ? '' | |
17 | ||
455f099b BB |
18 | if opts.hidden |
19 | @classList.add('vim-hidden-normal-mode-input') | |
20 | @mainEditorElement.parentNode.appendChild(this) | |
21 | else | |
22 | @panel = atom.workspace.addBottomPanel(item: this, priority: 100) | |
24c7594d BB |
23 | |
24 | @focus() | |
25 | @handleEvents() | |
26 | ||
27 | this | |
28 | ||
29 | handleEvents: -> | |
30 | if @singleChar? | |
455f099b | 31 | compositing = false |
24c7594d | 32 | @editorElement.getModel().getBuffer().onDidChange (e) => |
455f099b BB |
33 | @confirm() if e.newText and not compositing |
34 | @editorElement.addEventListener 'compositionstart', -> compositing = true | |
35 | @editorElement.addEventListener 'compositionend', -> compositing = false | |
24c7594d BB |
36 | else |
37 | atom.commands.add(@editorElement, 'editor:newline', @confirm.bind(this)) | |
38 | ||
39 | atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this)) | |
40 | atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this)) | |
41 | atom.commands.add(@editorElement, 'blur', @cancel.bind(this)) | |
42 | ||
43 | confirm: -> | |
44 | @value = @editorElement.getModel().getText() or @defaultText | |
45 | @viewModel.confirm(this) | |
46 | @removePanel() | |
47 | ||
48 | focus: -> | |
49 | @editorElement.focus() | |
50 | ||
51 | cancel: (e) -> | |
52 | @viewModel.cancel(this) | |
53 | @removePanel() | |
54 | ||
55 | removePanel: -> | |
56 | atom.workspace.getActivePane().activate() | |
455f099b BB |
57 | if @panel? |
58 | @panel.destroy() | |
59 | else | |
60 | this.remove() | |
24c7594d BB |
61 | |
62 | module.exports = | |
455f099b | 63 | document.registerElement("vim-normal-mode-input" |
24c7594d | 64 | extends: "div", |
455f099b | 65 | prototype: VimNormalModeInputElement.prototype |
24c7594d | 66 | ) |