Hello,
There is an existing sort action https://actions.getdrafts.com/a/1LX with the choice of ascending/descending.
The action puts large caps in sorted order at the beginning of the list, followed by small caps in sorted order, which is interesting in terms of a different way of conceiving lists
Is there a way to modify the script so that the action ignores caps, ie sorts the list without taking caps into account. Or is there a simpler way of sorting with Drafts ?
thank you
// sort
(() => {
const hasSelection = () => editor.getSelectedRange()[1] > 0;
const getText = () => {
const e = editor;
return hasSelection() ?
e.getTextInRange(...e.getSelectedLineRange()) :
e.getText();
};
const setText = (t) => {
const e = editor;
if (hasSelection()) {
const sel = e.getSelectedLineRange();
e.setTextInRange(...sel, t);
e.setSelectedRange(sel[0], t.length);
} else {
e.setText(t);
}
};
let l = getText().split('\n');
// remove blank lines
l = l.filter(l => l.trim());
if (unique) {
l = l.filter((v,i,a) => a.indexOf(v) === i);
}
l.sort();
if (desc) {
l.reverse();
}
setText(l.join('\n') + '\n');
})();