Backwards select between commas.

Script key: Backwards select between commas.

Posted by odornd



Label ,←,
Voice Over Backwards select between commas.
// This key is useful in navigating CSV (comma separated values) style documents. 

// Find the cursor
var selRange = getSelectedRange();
var beg = selRange[0];
var len = selRange[1];

/* Find the first comma or beginning-of-line after the cursor till the end of the draft. This position is relative to the cursor */

var findComma = /$|,/m;

// Get text before cursor so search

var textBeforeCursor = getTextInRange(0, beg);

//Search backwards: requires reversing our text

textBeforeCursor = textBeforeCursor.split('').reverse().join('');

// Find the poition of the first comma relative to the cursor

var firstCommaRelPos = findComma.exec(textBeforeCursor).index;

// Find second comma after cursor (backwards) and its relative position

textBeforeCursor = getTextInRange(0, beg - 1 - firstCommaRelPos);

textBeforeCursor = textBeforeCursor.split('').reverse().join('');

var secondCommaRelPos = findComma.exec(textBeforeCursor).index;

// Set the absolute postions for the text after the first comma

var firstCommaAbsPos = beg - firstCommaRelPos - 1;

var secondCommaAbsPos = beg - firstCommaRelPos - secondCommaRelPos - 1;

// Get the selection length
var selLen = firstCommaAbsPos - secondCommaAbsPos;

// Update selection
setSelectedRange(secondCommaAbsPos, selLen);


Keyboard shortcut None
Hide key Yes


comments powered by Disqus