<--
Outdent

Script key: Outdent

Posted by ComplexPoint

Install

Details

Label <--
Voice Over Outdent
Script
drafts = this;

var lstSelnRange = drafts.getSelectedRange(),
	lstLineRange = drafts.getSelectedLineRange(),

	iLinesStart = lstLineRange[0],
	iLinesChars = lstLineRange[1] ? lstLineRange[1] - 1 : 0,

	blnFirstOutdented = false,
	lngOutdented = 0,

	lstLines = drafts.getTextInRange(iLinesStart, iLinesChars)
	.split(/\n/).map(
		function (strLine, i) {
			if (strLine[0] === '\t'){
				if (i === 0) blnFirstOutdented = true;
				lngOutdented += 1;

				return strLine.slice(1);
			} else return strLine;
		}
	),
	lngStartAdjusted = (blnFirstOutdented ? 1 : 0);

drafts.setTextInRange(iLinesStart, iLinesChars, lstLines.join('\n'));
drafts.setSelectedRange(
	lstSelnRange[0] - lngStartAdjusted,
	lstSelnRange[1] - lngOutdented + lngStartAdjusted
);

Advanced

Keyboard shortcut Command+[
Hide key Yes

Discussion

comments powered by Disqus