From: Mike Lowis Date: Tue, 25 Oct 2016 20:25:11 +0000 (-0400) Subject: renamed Dot* to Sel in preparation for a new selection management module X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b23f9749502229a559c389115e60acdeeda026c3;p=projs%2Ftide.git renamed Dot* to Sel in preparation for a new selection management module --- diff --git a/edit.h b/edit.h index 1055664..b4262f8 100644 --- a/edit.h +++ b/edit.h @@ -249,8 +249,8 @@ enum ColorScheme { extern enum ColorScheme ColorBase; extern Buf Buffer; extern unsigned TargetCol; -extern unsigned DotBeg; -extern unsigned DotEnd; +extern unsigned SelBeg; +extern unsigned SelEnd; /* Configuration *****************************************************************************/ diff --git a/keyboard.c b/keyboard.c index d2c8453..3012a04 100644 --- a/keyboard.c +++ b/keyboard.c @@ -5,42 +5,42 @@ static void toggle_colors(void) { } 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; } @@ -63,15 +63,15 @@ static void quit(void) { } 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; } @@ -81,17 +81,17 @@ static void dot_change(void) { } 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); } /*****************************************************************************/ diff --git a/mouse.c b/mouse.c index 1cceaa4..615c625 100644 --- a/mouse.c +++ b/mouse.c @@ -7,71 +7,72 @@ void unused(MouseEvent* mevnt) { 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, @@ -129,8 +130,8 @@ static void handle_click(MouseEvent* mevnt) { 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) { diff --git a/screen.c b/screen.c index cb084cb..5cd464b 100644 --- a/screen.c +++ b/screen.c @@ -11,7 +11,7 @@ static unsigned fill_row(Buf* buf, unsigned row, unsigned pos) { screen_getrow(row)->off = pos; screen_clearrow(row); for (unsigned x = 0; x < NumCols;) { - uint32_t attr = (DotBeg <= pos && pos < DotEnd ? ATTR_SELECTED : ATTR_NORMAL); + uint32_t attr = (SelBeg <= pos && pos < SelEnd ? ATTR_SELECTED : ATTR_NORMAL); Rune r = buf_get(buf, pos++); x += screen_setcell(row, x, attr, r); if (buf_iseol(buf, pos-1)) break; diff --git a/tests/tests.c b/tests/tests.c index 0ed3712..d2e8f0a 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -5,8 +5,8 @@ Buf Buffer; unsigned CursorPos; unsigned TargetCol; -unsigned DotBeg; -unsigned DotEnd; +unsigned SelBeg; +unsigned SelEnd; enum ColorScheme ColorBase; void move_pointer(unsigned x, unsigned y) { diff --git a/xedit.c b/xedit.c index 0e4f282..2d2f3df 100644 --- a/xedit.c +++ b/xedit.c @@ -9,8 +9,8 @@ Buf Buffer; unsigned TargetCol = 0; -unsigned DotBeg = 0; -unsigned DotEnd = 0; +unsigned SelBeg = 0; +unsigned SelEnd = 0; enum ColorScheme ColorBase = DEFAULT_COLORSCHEME; XftColor Palette[CLR_COUNT][2]; struct { @@ -395,7 +395,7 @@ static void redraw(void) { /* update the screen buffer and retrieve cursor coordinates */ unsigned csrx, csry; - screen_update(&Buffer, DotEnd, &csrx, &csry); + screen_update(&Buffer, SelEnd, &csrx, &csry); /* flush the screen buffer */ unsigned nrows, ncols;