Move cursor to right by word

Script key: Move cursor to right by word

Posted by @onetapless

Install

Details

Label
Voice Over Move cursor to right by word
Script
// Script keys run short Javascripts
// For documentation and examples, visit:
// http://help.agiletortoise.com

var selRange = getSelectedRange();
var text = getText();
var selEndIndex = selRange[0] + selRange[1];

if (text.charAt(selEndIndex) === " ") {
  selEndIndex++;
  if (selRange[1] > 0) {
    selRange[1]++;
  }
}

var afterText = text.substring(selEndIndex);
var firstIndex = afterText.indexOf(" ");

if (selRange[1] > 0 && firstIndex !== -1) {
  var newSelLength = firstIndex + selRange[1];
  setSelectedRange(selRange[0], newSelLength);
} else if (selRange[1] === 0) {
  if (firstIndex !== -1) {
    setSelectedRange(firstIndex + selEndIndex, 0);
  } else {
    setSelectedRange(afterText.length + selEndIndex, 0);
  }
} else {
  setSelectedRange(selRange[0], selRange[1] + afterText.length);
}

//setSelectedRange(selEndIndex, selLength);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus