Edit text in the cursor line

This is a script for Drafts.

let [loc, len] = editor.getSelectedLineRange(),
  newStr = 'Hello World';
editor.setTextInRange(loc, len, newStr);