mw
Mark next word

Script key: Mark next word

Posted by Alexander Seidl, @a_aladin1001

Install

Details

Label mw
Voice Over Mark next word
Script
var selRange = getSelectedRange();
var regex = /\s/gi;
var mark_start, mark_length
var go = true

do {
  
  var text = getText();
  var beforeText = text.substring(0, selRange[0]);
  var afterText = text.substring(selRange[0]);
  var char_before = text.charAt(selRange[0]-1)
  var char_after = text.charAt(selRange[0])

  
  if ( char_before.match(regex) && char_after.match(regex) ) {
    setText( beforeText+afterText.substring(1) )
  } else {
    mark_start = Math.max(beforeText.lastIndexOf(" "),beforeText.lastIndexOf("\n"))+1
    var aftertext_indexofn = afterText.indexOf("\n")
    var aftertext_indexofs = afterText.indexOf(" ")
	if (aftertext_indexofn > -1 && aftertext_indexofs > -1) {
      mark_length = Math.min(aftertext_indexofs,aftertext_indexofn)+(selRange[0]-mark_start)
    } else if (aftertext_indexofn <= -1 && aftertext_indexofs <= -1) {
      mark_length = (text.length-mark_start)
    } else if (aftertext_indexofn <= -1 || aftertext_indexofs <= -1) {
      mark_length = Math.max(aftertext_indexofs,aftertext_indexofn)+(selRange[0]-mark_start)
    }
    
    go = false
  }
  
} while (go == true)


setSelectedRange(mark_start, mark_length)
//setSelectedText("")

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus