mirror of
https://github.com/atom/atom.git
synced 2026-02-15 00:55:14 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user