,→,
Select text between commas.

Script key: Select text between commas.

Posted by odornd

Install

Details

Label ,→,
Voice Over Select text between commas.
Script
// Select some text in between commas.
// This key is useful in navigating CSV style files. 


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

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

var findComma = /,|$/m;
var firstCommaRelPos = findComma.exec(getTextInRange(beg,getText().length)).index;


// Find second comma after cursor

var secondCommaRelPos = findComma.exec(getTextInRange(beg + firstCommaRelPos + 1, getText().length)).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 = secondCommaAbsPos - firstCommaAbsPos;


// Update selection
setSelectedRange(firstCommaAbsPos, selLen);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus