[s]
Select sentence

Script key: Select sentence

Posted by @elstudio

Install

Details

Label [s]
Voice Over Select sentence
Script
// ←[s]→ by @elstudio
// Expand selection to current sentence

var selRange = getSelectedRange();
var beg = selRange[0];
var len = selRange[1];

var preText = getTextInRange(0, beg - 1);

var postBeg = beg + len + 1;
var postText = getTextInRange(postBeg, getText().length);

var newBeg = 0;
var newEnd = 0;

// Search backwards
// Searching backward will require reversing our pre string and regexp
var revPunctuation = /\s+([\]\)"']?[\.?!]+)/m;
preText = preText.split('').reverse().join('');
//alert(preText);
var backward = revPunctuation.exec(preText);
if (backward !== null) {
  newBeg = backward.index + backward[1].length;
}

// Search forward
var punctuation = /([\.?!]+[\]\)"']?\s)\s*/m;
var forward = punctuation.exec(postText);
if (forward !== null) {
  newEnd = forward.index + forward[1].length
}

// Update selection
setSelectedRange(beg - newBeg, len + 1 + newEnd + newBeg);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus