✪ Trim
Remove leading and trailing white space

Script key: Remove leading and trailing white space

Posted by @GilsDesk

Install

Details

Label ✪ Trim
Voice Over Remove leading and trailing white space
Script
// Trim selected text, or all text if none selected, to remove leading or trailing spaces
// Cursor returns to start of Draft if entire Draft was trimmed. 
// Cursor returns to start of selected text if text was selected prior to running. 

var s = getSelectedText();
if (s.length > 0) { 
var sel_start = getSelectedRange();
var res = s.replace(/^[ \t]+|[ \t]+$/gm,'');
setSelectedText(res); 
setSelectedRange(sel_start[0],0);
} else {
var t = getText();
var res = t.replace(/^[ \t]+|[ \t]+$/gm,'');
setText(res);
setSelectedRange(0,0);
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus