mirror of
https://github.com/atom/atom.git
synced 2026-02-13 08:04:56 -05:00
Add initial editor command super class
This can be extended by extensions targetted towards acting on text inside the editor and not contributing any UI
This commit is contained in:
33
src/extensions/editor-command.coffee
Normal file
33
src/extensions/editor-command.coffee
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports =
|
||||
class EditorCommand
|
||||
|
||||
@activate: (rootView) ->
|
||||
keymaps = @getKeymaps()
|
||||
return unless keymaps
|
||||
|
||||
window.keymap.bindKeys '.editor', keymaps
|
||||
|
||||
for editor in rootView.getEditors()
|
||||
@subscribeToEditor(rootView, editor)
|
||||
|
||||
rootView.on 'editor-open', (e, editor) =>
|
||||
@subscribeToEditor(rootView, editor)
|
||||
|
||||
@subscribeToEditor: (rootView, editor) ->
|
||||
keymaps = @getKeymaps(rootView, editor)
|
||||
return unless keymaps
|
||||
|
||||
for key, event of keymaps
|
||||
editor.on event, => @execute(editor, event)
|
||||
|
||||
@alterSelection: (editor, transform) ->
|
||||
selection = editor.getSelection()
|
||||
return false if selection.isEmpty()
|
||||
|
||||
range = selection.getBufferRange()
|
||||
reverse = selection.isReversed()
|
||||
text = transform(editor.getTextInRange(range))
|
||||
return false if text is null or text is undefined
|
||||
editor.insertText(text)
|
||||
selection.setBufferRange(range, {reverse})
|
||||
true
|
||||
Reference in New Issue
Block a user