Cursor line begin

Script key: Cursor line begin

Posted by Xor

Install

Details

Label
Voice Over Cursor line begin
Script
var text = getText()
var n = text.length
var selRange = getSelectedRange()

var p = selRange[0]
var q = p + selRange[1]

selectLine()
if (p && p === selRange[0]) {
  --p
}

setSelectedRange(p, 0)

function selectLine() {
  var i = p
  var delim = /^[\n]$/
  var space = /^[\s]$/

  var b = p
  
  while (i > 0) {
    if (delim.test(text[i - 1]))
      break
  
    --i
    if (!space.test(text[i]))
      b = i
  }
  
  var j = q
  
  while (j < n) {
    if (delim.test(text[j]))
      break
    ++j
  }

  ++j
  
  //if (j-i)
  //  setSelectedRange(i, j-i)
  //p = i

  if (p === b)
    p = i
  else
    p = b
  
  q = j
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus