Action

Select Word (Key)

Posted by Tethys, Last update over 6 years ago

Select Word

A custom key action that selects the word nearest the editing caret.

Add desired shortcut for external keyboard use.

Steps

  • script

    var text = editor.getText()
    var selRange = editor.getSelectedRange()
    
    var n = text.length
    
    var i = selRange[0]
    //var delim = /^[^\w]$/
    var delim = /^[\s]$/
    
    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
    }
    
    if (j-i)
      editor.setSelectedRange(i, j-i)
    /*else if (i)
      editor.setSelectedRange(i-1, 1)
    else 
      editor.setSelectedRange(0, 1)*/

Options

  • After Success Nothing
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.