Insert text and select it?


I’m attempting to make a simple function to create a Markdown-formatted link from selected text, such that

selected text


[selected text](URL)

but I’d like the “URL” text to be selected (such that if you then start typing your link, it will replace that text with your link).

I’ve gotten it to a point where I can get the text inserted:

editor = atom.workspaceView.getActiveView().getEditor()
selection = editor.getLastSelection()
curText = selection.getText()

But then how do I move the editor’s cursor/selection to “URL”?



I would use selection.getBufferRange() and selection.setBufferRange() to modify the selection you already have to exactly where you want it to be.