How do I clear selection with custom command in init.coffee


#1

I’m trying to make a macro to insert '* ’ to beginning of each line in selection. It looks like this:

atom.commands.add 'atom-text-editor', 'custom:split-home', ->
 editor = atom.workspace.getActiveTextEditor()
 editor.selectAll()
 editor.splitSelectionsIntoLines()
 editor.moveToBeginningOfScreenLine()

afterwards I need to clear selection and instert text '* '. Something like that:

editor.clear() # get error because it's not an editor method but a `selection` object method
editor.insertText("* ")    

And I can’t get around it with atom.commands.dispatch() because there is no separate command to clear selection.
So, how do I access this method properly?


#2

Tried editor.insertText("* ") and it added symbols, not replaced selection. But I’m still intrested in how to access extended classed properly.


#3

editor.getLastSelection().clear() will eliminate the most recent selection.