Move EditorCommand helpers elsewhere

RootView and Editor now have helpers that support
binding events to callbacks, binding a callback to
all current and future editors, and replacing the
selected text via a transforming callback.
This commit is contained in:
Kevin Sawicki
2012-10-10 18:41:12 -07:00
parent 1fa32c48e7
commit d4aeb1bb95
10 changed files with 162 additions and 176 deletions

View File

@@ -965,3 +965,20 @@ class Editor extends View
@find('pre.line.cursor-line').removeClass('cursor-line')
if @getSelection().isSingleScreenLine()
@find("pre.line:eq(#{screenRow})").addClass('cursor-line')
bindToKeyedEvent: (key, event, callback) ->
binding = {}
binding[key] = event
window.keymap.bindKeys '.editor', binding
@on event, =>
callback(this, event)
replaceSelectedText: (replaceFn) ->
selection = @getSelection()
return false if selection.isEmpty()
text = replaceFn(@getTextInRange(selection.getBufferRange()))
return false if text is null or text is undefined
@insertText(text, select: true)
true

View File

@@ -232,3 +232,10 @@ class RootView extends View
saveAll: ->
editor.save() for editor in @getEditors()
eachEditor: (callback) ->
for editor in @getEditors()
callback(editor)
@on 'editor-open', (e, editor) ->
callback(editor)