^ A'
Move to first non-whitespace of line, or expand selection to it

Script key: Move to first non-whitespace of line, or expand selection to it

Posted by Puttin

Install

Details

Label ^ A'
Voice Over Move to first non-whitespace of line, or expand selection to it
Script
// Move to first non-whitespace of line, or expand selection to it.

var range = getSelectedRange();
var line_range = getSelectedLineRange();
var line_text = getTextInRange(line_range[0], line_range[1]);
var firstNonWhitespaceIndex = firstNonWhitespaceIndex(line_text);

if (isSelect() === true) {
  setSelectedRange(firstNonWhitespaceIndex, range[0] + range[1] - firstNonWhitespaceIndex);
} else {
  setSelectedRange(firstNonWhitespaceIndex, 0 );
}

function isSelect() {
  if (getSelectedText().length > 0) {
    return true;
  } else {
    return false;
  }
}

function firstNonWhitespaceIndex(text) {
  return /\S/.exec(text).index;
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus