⌘F
Find selected

Script key: Find selected

Posted by cprichard

Install

Details

Label ⌘F
Voice Over Find selected
Script
// Script keys run short Javascripts
// For documentation and examples, visit:
// http://help.agiletortoise.com

// Find the current line starting at the beginning of the draft or find the selected text further down in the draft.
// Derived from http://drafts4-actions.agiletortoise.com/k/1gE

var search_term, search_index, line_range, match, length;

if ( isSelect() === true ) {
  search_term = getSelectedText();
  search_index = getSelectedRange()[0] + 1;
} else {
  line_range = getSelectedLineRange();
  search_term = getTextInRange( line_range[0], line_range[1] );
  search_index = 0;
}
search_term = search_term.replace( /\r?\n/g, '' );
match = getText().indexOf( search_term, search_index );
length = search_term.length;
if ( match > 0 ) {
  setSelectedRange( match, length );
  alert("Found!");     // you might have to scroll to see the selected text
} else {
  setSelectedRange(search_index-1,search_term.length);
  alert("Not Found!"); // selected text will remain selected
}

function isSelect() {
  if ( getSelectedText().length > 0 ) {
    return true;
  } else {
    return false;
  }
}

Advanced

Keyboard shortcut Control+F
Hide key Yes

Discussion

comments powered by Disqus