* implement tctl command
* gap buffer does not handle UTF-8 currently
* Line - Get the current line number(s) containing the selection
+
+## UNCERTAIN
+
* refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend)
* encode EOL setting in log entries?
* centering logic in view.c seems slightly broken
void buf_setcol(Buf* buf);
size_t buf_selbeg(Buf* buf);
+size_t buf_selend(Buf* buf);
size_t buf_selsz(Buf* buf);
void buf_selln(Buf* buf);
void buf_selclr(Buf* buf, int dir);
return (sel.beg < sel.end ? sel.beg : sel.end);
}
+size_t buf_selend(Buf* buf) {
+ Sel sel = buf_getsel(buf);
+ return (sel.beg < sel.end ? sel.end : sel.beg);
+}
+
size_t buf_selsz(Buf* buf) {
Sel sel = buf_getsel(buf);
return sel.end - sel.beg;
}
void buf_selln(Buf* buf) {
- /* swap the direction of the selection so beg < end */
- if (buf->selection.beg > buf->selection.end) {
- size_t off = buf->selection.beg;
- buf->selection.beg = buf->selection.end;
- buf->selection.end = off;
- }
-
/* Expand the selection to completely select the lines covered */
- buf->selection.beg = buf_bol(buf, buf->selection.beg);
- if (!buf_iseol(buf, buf->selection.end-1) || buf->selection.end == buf->selection.beg) {
- buf->selection.end = buf_eol(buf, buf->selection.end);
- buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
+ Sel sel = (Sel){ .beg = buf_selbeg(buf), .end = buf_selend(buf) };
+ sel.beg = buf_bol(buf, sel.beg);
+ if (!buf_iseol(buf, sel.end-1) || sel.end == sel.beg) {
+ sel.end = buf_eol(buf, sel.end);
+ sel.end = buf_byrune(buf, sel.end, RIGHT);
}
+ buf->selection = sel;
}
void buf_selclr(Buf* buf, int dir) {