Action
Sort by Length
Posted by sylumer,
Last update
about 2 years ago
- Unlisted
Sort selection by length, or if no selection, defaults to the entire draft.
Steps
-
script
// Initialise let intStart = 0; let intLen = 0; // Get selection or entire draft if no selection [intStart, intLen] = editor.getSelectedLineRange(); let intSelLen = editor.getSelectedRange()[1]; let astrSelectedLines = []; if (intSelLen < 2) astrSelectedLines = draft.lines; else astrSelectedLines = editor.getTextInRange(intStart, intLen).split("\n"); // Sort - first by length, then alphabetically let astrSorted = astrSelectedLines.sort((a, b) => a.toString().length - b.toString().length || a.toString().localeCompare(b)); // Replace original text if (intSelLen < 2) editor.setText(astrSorted.join("\n")); else editor.setTextInRange(intStart, intLen, astrSorted.join("\n"));
Options
-
After Success Default Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.