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
|
||||
)
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
{View} = require 'space-pen'
|
||||
{TextEditorView} = require 'atom-space-pen-views'
|
||||
|
||||
module.exports =
|
||||
class ExCommandModeInputView extends View
|
||||
@content: ->
|
||||
@div class: 'command-mode-input', =>
|
||||
@div class: 'editor-container', outlet: 'editorContainer', =>
|
||||
@subview 'editor', new TextEditorView(mini: true)
|
||||
|
||||
initialize: (@viewModel, opts = {})->
|
||||
if opts.class?
|
||||
@editorContainer.addClass opts.class
|
||||
|
||||
if opts.hidden
|
||||
@editorContainer.addClass 'hidden-input'
|
||||
|
||||
@singleChar = opts.singleChar
|
||||
@defaultText = opts.defaultText ? ''
|
||||
|
||||
@panel = atom.workspace.addBottomPanel(item: this, priority: 100)
|
||||
|
||||
@focus()
|
||||
@handleEvents()
|
||||
|
||||
handleEvents: ->
|
||||
if @singleChar?
|
||||
@editor.find('input').on 'textInput', @autosubmit
|
||||
@editor.on 'core:confirm', @confirm
|
||||
@editor.on 'core:cancel', @cancel
|
||||
@editor.on 'blur', @cancel
|
||||
|
||||
stopHandlingEvents: ->
|
||||
if @singleChar?
|
||||
@editor.find('input').off 'textInput', @autosubmit
|
||||
@editor.off 'core:confirm', @confirm
|
||||
@editor.off 'core:cancel', @cancel
|
||||
@editor.off 'blur', @cancel
|
||||
|
||||
autosubmit: (event) =>
|
||||
@editor.setText(event.originalEvent.data)
|
||||
@confirm()
|
||||
|
||||
confirm: =>
|
||||
@value = @editor.getText() or @defaultText
|
||||
@viewModel.confirm(@)
|
||||
@remove()
|
||||
|
||||
focus: =>
|
||||
@editorContainer.find('.editor').focus()
|
||||
|
||||
cancel: (e) =>
|
||||
@viewModel.cancel(@)
|
||||
@remove()
|
||||
|
||||
remove: =>
|
||||
@stopHandlingEvents()
|
||||
atom.workspace.getActivePane().activate()
|
||||
@panel.destroy()
|
||||
|
|
@ -6,11 +6,11 @@ class ExViewModel extends ViewModel
|
|||
super(@exCommand, class: 'command')
|
||||
@historyIndex = -1
|
||||
|
||||
@view.editor.on('core:move-up', @increaseHistoryEx)
|
||||
@view.editor.on('core:move-down', @decreaseHistoryEx)
|
||||
atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistoryEx)
|
||||
atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistoryEx)
|
||||
|
||||
restoreHistory: (index) ->
|
||||
@view.editor.setText(@history(index).value)
|
||||
@view.editorElement.getModel().setText(@history(index).value)
|
||||
|
||||
history: (index) ->
|
||||
@exState.getExHistoryItem(index)
|
||||
|
|
@ -24,7 +24,7 @@ class ExViewModel extends ViewModel
|
|||
if @historyIndex <= 0
|
||||
# get us back to a clean slate
|
||||
@historyIndex = -1
|
||||
@view.editor.setText('')
|
||||
@view.editorElement.getModel().setText('')
|
||||
else
|
||||
@historyIndex -= 1
|
||||
@restoreHistory(@historyIndex)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class Ex
|
|||
filePath = filePath.trim()
|
||||
if filePath.indexOf(' ') isnt -1
|
||||
throw new CommandError('Only one file name allowed')
|
||||
buffer = atom.workspace.getActiveEditor().buffer
|
||||
buffer = atom.workspace.getActiveTextEditor().buffer
|
||||
filePath = buffer.getPath() if filePath is ''
|
||||
buffer.setPath(getFullPath(filePath))
|
||||
buffer.load()
|
||||
|
|
@ -105,7 +105,7 @@ class Ex
|
|||
e: (args...) => @edit(args...)
|
||||
|
||||
enew: ->
|
||||
buffer = atom.workspace.getActiveEditor().buffer
|
||||
buffer = atom.workspace.getActiveTextEditor().buffer
|
||||
buffer.setPath(undefined)
|
||||
buffer.load()
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ class Ex
|
|||
deferred = Promise.defer()
|
||||
|
||||
pane = atom.workspace.getActivePane()
|
||||
editor = atom.workspace.getActiveEditor()
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
if atom.workspace.getActiveTextEditor().getPath() isnt undefined
|
||||
if filePath.length > 0
|
||||
editorPath = editor.getPath()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
ExCommandModeInputView = require './ex-command-mode-input-view'
|
||||
ExCommandModeInputElement = require './ex-command-mode-input-element'
|
||||
|
||||
class ViewModel
|
||||
constructor: (@command, opts={}) ->
|
||||
{@editor, @exState} = @command
|
||||
|
||||
@view = new ExCommandModeInputView(@, opts)
|
||||
@view = new ExCommandModeInputElement().initialize(@, opts)
|
||||
@editor.commandModeInputView = @view
|
||||
@exState.onDidFailToExecute => @view.remove()
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"repository": "https://github.com/lloeki/ex-mode",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"atom": ">=0.174.0 <2.0.0"
|
||||
"atom": ">=0.200.0 <2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"underscore-plus": "1.x",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue