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')
|
super(@exCommand, class: 'command')
|
||||||
@historyIndex = -1
|
@historyIndex = -1
|
||||||
|
|
||||||
@view.editor.on('core:move-up', @increaseHistoryEx)
|
atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistoryEx)
|
||||||
@view.editor.on('core:move-down', @decreaseHistoryEx)
|
atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistoryEx)
|
||||||
|
|
||||||
restoreHistory: (index) ->
|
restoreHistory: (index) ->
|
||||||
@view.editor.setText(@history(index).value)
|
@view.editorElement.getModel().setText(@history(index).value)
|
||||||
|
|
||||||
history: (index) ->
|
history: (index) ->
|
||||||
@exState.getExHistoryItem(index)
|
@exState.getExHistoryItem(index)
|
||||||
|
|
@ -24,7 +24,7 @@ class ExViewModel extends ViewModel
|
||||||
if @historyIndex <= 0
|
if @historyIndex <= 0
|
||||||
# get us back to a clean slate
|
# get us back to a clean slate
|
||||||
@historyIndex = -1
|
@historyIndex = -1
|
||||||
@view.editor.setText('')
|
@view.editorElement.getModel().setText('')
|
||||||
else
|
else
|
||||||
@historyIndex -= 1
|
@historyIndex -= 1
|
||||||
@restoreHistory(@historyIndex)
|
@restoreHistory(@historyIndex)
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ class Ex
|
||||||
filePath = filePath.trim()
|
filePath = filePath.trim()
|
||||||
if filePath.indexOf(' ') isnt -1
|
if filePath.indexOf(' ') isnt -1
|
||||||
throw new CommandError('Only one file name allowed')
|
throw new CommandError('Only one file name allowed')
|
||||||
buffer = atom.workspace.getActiveEditor().buffer
|
buffer = atom.workspace.getActiveTextEditor().buffer
|
||||||
filePath = buffer.getPath() if filePath is ''
|
filePath = buffer.getPath() if filePath is ''
|
||||||
buffer.setPath(getFullPath(filePath))
|
buffer.setPath(getFullPath(filePath))
|
||||||
buffer.load()
|
buffer.load()
|
||||||
|
|
@ -105,7 +105,7 @@ class Ex
|
||||||
e: (args...) => @edit(args...)
|
e: (args...) => @edit(args...)
|
||||||
|
|
||||||
enew: ->
|
enew: ->
|
||||||
buffer = atom.workspace.getActiveEditor().buffer
|
buffer = atom.workspace.getActiveTextEditor().buffer
|
||||||
buffer.setPath(undefined)
|
buffer.setPath(undefined)
|
||||||
buffer.load()
|
buffer.load()
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ class Ex
|
||||||
deferred = Promise.defer()
|
deferred = Promise.defer()
|
||||||
|
|
||||||
pane = atom.workspace.getActivePane()
|
pane = atom.workspace.getActivePane()
|
||||||
editor = atom.workspace.getActiveEditor()
|
editor = atom.workspace.getActiveTextEditor()
|
||||||
if atom.workspace.getActiveTextEditor().getPath() isnt undefined
|
if atom.workspace.getActiveTextEditor().getPath() isnt undefined
|
||||||
if filePath.length > 0
|
if filePath.length > 0
|
||||||
editorPath = editor.getPath()
|
editorPath = editor.getPath()
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
ExCommandModeInputView = require './ex-command-mode-input-view'
|
ExCommandModeInputElement = require './ex-command-mode-input-element'
|
||||||
|
|
||||||
class ViewModel
|
class ViewModel
|
||||||
constructor: (@command, opts={}) ->
|
constructor: (@command, opts={}) ->
|
||||||
{@editor, @exState} = @command
|
{@editor, @exState} = @command
|
||||||
|
|
||||||
@view = new ExCommandModeInputView(@, opts)
|
@view = new ExCommandModeInputElement().initialize(@, opts)
|
||||||
@editor.commandModeInputView = @view
|
@editor.commandModeInputView = @view
|
||||||
@exState.onDidFailToExecute => @view.remove()
|
@exState.onDidFailToExecute => @view.remove()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
"repository": "https://github.com/lloeki/ex-mode",
|
"repository": "https://github.com/lloeki/ex-mode",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"atom": ">=0.174.0 <2.0.0"
|
"atom": ">=0.200.0 <2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"underscore-plus": "1.x",
|
"underscore-plus": "1.x",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue