}
static void cursor_up(void) {
- DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, -1);
- DotBeg = DotEnd = buf_setcol(&Buffer, DotEnd, TargetCol);
+ SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, -1);
+ SelBeg = SelEnd = buf_setcol(&Buffer, SelEnd, TargetCol);
}
static void cursor_dn(void) {
- DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, 1);
- DotBeg = DotEnd = buf_setcol(&Buffer, DotEnd, TargetCol);
+ SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, 1);
+ SelBeg = SelEnd = buf_setcol(&Buffer, SelEnd, TargetCol);
}
static void cursor_left(void) {
- DotBeg = DotEnd = buf_byrune(&Buffer, DotEnd, -1);
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ SelBeg = SelEnd = buf_byrune(&Buffer, SelEnd, -1);
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
static void cursor_right(void) {
- DotBeg = DotEnd = buf_byrune(&Buffer, DotEnd, 1);
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ SelBeg = SelEnd = buf_byrune(&Buffer, SelEnd, 1);
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
static void cursor_bol(void) {
- DotBeg = DotEnd = buf_bol(&Buffer, DotEnd);
+ SelBeg = SelEnd = buf_bol(&Buffer, SelEnd);
TargetCol = 0;
}
static void cursor_eol(void) {
- DotBeg = DotEnd = buf_eol(&Buffer, DotEnd);
+ SelBeg = SelEnd = buf_eol(&Buffer, SelEnd);
TargetCol = (unsigned)-1;
}
static void insert_before(void) {
- DotEnd = DotBeg;
+ SelEnd = SelBeg;
Buffer.insert_mode = true;
}
static void insert_after(void) {
- DotBeg = ++DotEnd;
+ SelBeg = ++SelEnd;
Buffer.insert_mode = true;
}
}
static void dot_delete(void) {
- if (DotEnd == buf_end(&Buffer)) return;
- size_t n = DotEnd - DotBeg;
+ if (SelEnd == buf_end(&Buffer)) return;
+ size_t n = SelEnd - SelBeg;
bool insert = Buffer.insert_mode;
if (!insert || !n) n++;
Buffer.insert_mode = true;
for (size_t i = 0; i < n; i++)
- buf_del(&Buffer, DotBeg);
- DotEnd = DotBeg;
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ buf_del(&Buffer, SelBeg);
+ SelEnd = SelBeg;
+ TargetCol = buf_getcol(&Buffer, SelEnd);
Buffer.insert_mode = insert;
}
}
static void dot_backspace(void) {
- if (DotBeg > 0 && DotBeg == DotEnd) DotBeg--;
- while (DotBeg < DotEnd)
- buf_del(&Buffer, --DotEnd);
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ if (SelBeg > 0 && SelBeg == SelEnd) SelBeg--;
+ while (SelBeg < SelEnd)
+ buf_del(&Buffer, --SelEnd);
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
static void insert(Rune r) {
if (!Buffer.insert_mode) return;
- buf_ins(&Buffer, DotEnd++, r);
- DotBeg = DotEnd;
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ buf_ins(&Buffer, SelEnd++, r);
+ SelBeg = SelEnd;
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
/*****************************************************************************/
void move_cursor(MouseEvent* mevnt) {
if (mevnt->y == 0) return;
- DotBeg = DotEnd = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ SelBeg = SelEnd = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
void bigword(MouseEvent* mevnt) {
(void)mevnt;
- unsigned mbeg = DotEnd, mend = DotEnd;
+ unsigned mbeg = SelEnd, mend = SelEnd;
for (; !isblank(buf_get(&Buffer, mbeg-1)); mbeg--);
for (; !isblank(buf_get(&Buffer, mend)); mend++);
- DotBeg = mbeg, DotEnd = mend-1;
+ SelBeg = mbeg, SelEnd = mend-1;
}
void selection(MouseEvent* mevnt) {
(void)mevnt;
- unsigned bol = buf_bol(&Buffer, DotEnd);
- Rune r = buf_get(&Buffer, DotEnd);
- if (DotEnd == bol || r == '\n' || r == RUNE_CRLF) {
- DotBeg = bol;
- DotEnd = buf_eol(&Buffer, DotEnd);
+ unsigned bol = buf_bol(&Buffer, SelEnd);
+ Rune r = buf_get(&Buffer, SelEnd);
+ if (SelEnd == bol || r == '\n' || r == RUNE_CRLF) {
+ SelBeg = bol;
+ SelEnd = buf_eol(&Buffer, SelEnd);
} else if (isword(r)) {
- DotBeg = buf_bow(&Buffer, DotEnd);
- DotEnd = buf_eow(&Buffer, DotEnd);
- if (Buffer.insert_mode) DotEnd++;
+ SelBeg = buf_bow(&Buffer, SelEnd);
+ SelEnd = buf_eow(&Buffer, SelEnd);
+ if (Buffer.insert_mode) SelEnd++;
} else if (r == '(' || r == ')') {
- DotBeg = buf_lscan(&Buffer, DotEnd, '(');
- DotEnd = buf_rscan(&Buffer, DotEnd, ')');
- if (Buffer.insert_mode) DotEnd++;
+ SelBeg = buf_lscan(&Buffer, SelEnd, '(');
+ SelEnd = buf_rscan(&Buffer, SelEnd, ')');
+ if (Buffer.insert_mode) SelEnd++;
} else if (r == '[' || r == ']') {
- DotBeg = buf_lscan(&Buffer, DotEnd, '[');
- DotEnd = buf_rscan(&Buffer, DotEnd, ']');
- if (Buffer.insert_mode) DotEnd++;
+ SelBeg = buf_lscan(&Buffer, SelEnd, '[');
+ SelEnd = buf_rscan(&Buffer, SelEnd, ']');
+ if (Buffer.insert_mode) SelEnd++;
} else if (r == '{' || r == '}') {
- DotBeg = buf_lscan(&Buffer, DotEnd, '{');
- DotEnd = buf_rscan(&Buffer, DotEnd, '}');
- if (Buffer.insert_mode) DotEnd++;
+ SelBeg = buf_lscan(&Buffer, SelEnd, '{');
+ SelEnd = buf_rscan(&Buffer, SelEnd, '}');
+ if (Buffer.insert_mode) SelEnd++;
} else {
bigword(mevnt);
}
}
void search(MouseEvent* mevnt) {
- unsigned clickpos = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
- if (clickpos < DotBeg || clickpos > DotEnd) {
+ unsigned clickpos = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+ if (clickpos < SelBeg || clickpos > SelEnd) {
move_cursor(mevnt);
selection(mevnt);
+ } else {
+ buf_find(&Buffer, &SelBeg, &SelEnd);
}
- buf_find(&Buffer, &DotBeg, &DotEnd);
unsigned x, y;
- screen_update(&Buffer, DotEnd, &x, &y);
+ screen_update(&Buffer, SelEnd, &x, &y);
extern void move_pointer(unsigned x, unsigned y);
move_pointer(x, y);
+
}
void scrollup(MouseEvent* mevnt) {
(void)mevnt;
- DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, -ScrollLines);
+ SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, -ScrollLines);
}
void scrolldn(MouseEvent* mevnt) {
(void)mevnt;
- DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, ScrollLines);
+ SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, ScrollLines);
}
/*****************************************************************************/
-
enum {
SINGLE_CLICK = 0,
DOUBLE_CLICK,
static void handle_drag(MouseEvent* mevnt) {
if (mevnt->y == 0 || mevnt->button != MOUSE_LEFT) return;
- DotEnd = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
- TargetCol = buf_getcol(&Buffer, DotEnd);
+ SelEnd = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+ TargetCol = buf_getcol(&Buffer, SelEnd);
}
void handle_mouse(MouseEvent* mevnt) {