indent

Script key: indent

Posted by Xor

Install

Details

Label
Voice Over indent
Script
var text = getText()
var n = text.length
var selRange = getSelectedRange()

var p, q

var selectedText = text.substr(selRange[0], selRange[1])

var indentSize = 2
var indentStr = ""
for (var i = 0; i < indentSize; ++i) {
  indentStr += ' '
}

var lines = selectedText.split('\n')
for (var i = 1; i < lines.length; ++i) {
  lines[i] = indentStr + lines[i]
}

selectedText = lines.join('\n')
setSelectedText(selectedText)

selectLine()
setSelectedRange(p, 0)
var shift = 2

setSelectedText(indentStr)

setSelectedRange(selRange[0] + shift, selectedText.length)




function selectLine() {
 
  
  var i = selRange[0]
  var delim = /^[\n]$/
  
  while (i > 0) {
    if (delim.test(text[i - 1]))
      break
  
    --i
  }
  
  var j = selRange[0]//+selRange[1]
  
  while (j < n) {
    if (delim.test(text[j]))
      break
    ++j
  }

  ++j

  p = i
  q = j
  
  //if (j-i)
  //  setSelectedRange(i, j-i)
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus