buf_load(buf, path);
}
+static Sel selswap(Sel sel) {
+ size_t off = sel.beg;
+ sel.beg = sel.end, sel.end = off;
+ return sel;
+}
+
static void trim_whitespace(Buf* buf) {
if (!TrimOnSave || !buf_end(buf)) return;
Sel sel = buf->selection;
+ bool swapped = (sel.beg > sel.end);
+ if (swapped) sel = selswap(sel);
unsigned prev = 1;
buf->selection.beg = buf->selection.end = 0;
while (buf->selection.end < buf_end(buf) && prev != buf->selection.end) {
/* move to the next character */
prev = buf->selection.end;
buf->selection.end = buf_byrune(buf, buf->selection.end, +1);
- }
+ }
+ if (swapped) sel = selswap(sel);
buf->selection = sel;
}