Previous line

Script key: Previous line

See also the companion Next line key

Posted by agiletortoise

Install

Details

Label
Voice Over Previous line
Script
// Move cursor to the previous line

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

var pLineStart = lnRange[0];
var startDiff = selRange[0] - pLineStart;
var flFirstFound = false;
var prevLnLength = 0;

while (pLineStart > 0) {
  if	 (text[pLineStart-1] == '\n') {
    if (flFirstFound) {
      break;
    }
    else {
      prevLnLength++;
      pLineStart--;
      flFirstFound = true;
    }
  }  
  else {
    prevLnLength++;
    pLineStart--;
  }
}
if (prevLnLength >= startDiff) {
  pLineStart += startDiff;
}
else {
  pLineStart += prevLnLength - 1;
}

if (pLineStart < 0) { pLineStart = 0; }
setSelectedRange(pLineStart,0);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus