Move cursor to left by word

Script key: Move cursor to left by word

Posted by @onetapless

Install

Details

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

var selRange = getSelectedRange();
var text = getText();

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

var beforeText = text.substring(0, selRange[0]);
var lastIndex = beforeText.lastIndexOf(" ") + 1;

if (selRange[1] > 0) {
  var newSelLength = selRange[1] + (selRange[0] - lastIndex);
  setSelectedRange(lastIndex, newSelLength);
} else if (selRange[1] === 0) {
  setSelectedRange(lastIndex, 0);
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus