James Patterson James Patterson - 11 months ago 47
Javascript Question

Javascript add text to the head of document

I am writing a simple Atom.io package and would like to add a generic string to the head of the document using JavaScript :

var editor = atom.workspace.getActiveTextEditor();
if (editor) {
console.log("Package Active");
var selection = editor.getSelectedText();
editor.insertText("Sample Text" + selection);

I can not understand why the text is being inserted at the position of the cursor and not at the head of the document.


Reposition the cursor to the head of the page using:


Then add the desired text using:

  editor.insertText("Sample Text");