From: Michael D. Lowis Date: Fri, 2 Dec 2016 01:49:32 +0000 (-0500) Subject: implemented navigation and deletion by word X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e15a7fa3a9e170a8997bd08003d7f7daccadc69b;p=projs%2Ftide.git implemented navigation and deletion by word --- diff --git a/inc/edit.h b/inc/edit.h index a124935..2bd4971 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -73,40 +73,13 @@ void buf_find(Buf* buf, size_t* beg, size_t* end); void buf_findstr(Buf* buf, char* str, size_t* beg, size_t* end); unsigned buf_end(Buf* buf); unsigned buf_byrune(Buf* buf, unsigned pos, int count); +unsigned buf_byword(Buf* buf, unsigned pos, int count); unsigned buf_byline(Buf* buf, unsigned pos, int count); unsigned buf_getcol(Buf* buf, unsigned pos); unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col); void buf_lastins(Buf* buf, size_t* beg, size_t* end); void buf_loglock(Buf* buf); -/* -void buf_load(Buf* buf, char* path); -void buf_save(Buf* buf); -void buf_init(Buf* buf); -void buf_ins(Buf* buf, Sel csr, Rune); -void buf_del(Buf* buf, Sel csr); -Sel buf_undo(Buf* buf, Sel csr); -Sel buf_redo(Buf* buf, Sel csr); -Rune buf_get(Buf* buf, Sel csr); -void buf_setlocked(Buf* buf, bool locked); -bool buf_locked(Buf* buf); -bool buf_iseol(Buf* buf, Sel csr); -Sel buf_bol(Buf* buf, Sel csr); -Sel buf_eol(Buf* buf, Sel csr); -Sel buf_bow(Buf* buf, Sel csr); -Sel buf_eow(Buf* buf, Sel csr); -Sel buf_lscan(Buf* buf, Sel csr, Rune r); -Sel buf_rscan(Buf* buf, Sel csr, Rune r); -Sel buf_find(Buf* buf, Sel csr); -Sel buf_end(Buf* buf); -Sel buf_byrune(Buf* buf, Sel csr, int count); -Sel buf_byline(Buf* buf, Sel csr, int count); -Sel buf_getcol(Buf* buf, Sel csr); -Sel buf_setcol(Buf* buf, Sel csr, unsigned col); -char* buf_getstr(Buf* buf, Sel csr); -Sel buf_putstr(Buf* buf, Sel csr, char* str); -*/ - /* Charset Handling *****************************************************************************/ enum { @@ -160,6 +133,7 @@ void view_resize(View* view, size_t nrows, size_t ncols); void view_update(View* view, size_t* csrx, size_t* csry); Row* view_getrow(View* view, size_t row); void view_byrune(View* view, int move, bool extsel); +void view_byword(View* view, int move, bool extsel); void view_byline(View* view, int move, bool extsel); void view_setcursor(View* view, size_t row, size_t col); void view_selext(View* view, size_t row, size_t col); diff --git a/libedit/buf.c b/libedit/buf.c index 7cf20a7..658cd19 100644 --- a/libedit/buf.c +++ b/libedit/buf.c @@ -361,6 +361,20 @@ unsigned buf_byrune(Buf* buf, unsigned pos, int count) { return pos; } +unsigned buf_byword(Buf* buf, unsigned off, int count) { + int move = (count < 0 ? -1 : 1); + unsigned end = buf_end(buf); + if (move < 0) { + for (; off > 0 && !risword(buf_get(buf, off-1)); off--); + for (; off > 0 && risword(buf_get(buf, off-1)); off--); + } else { + for (; off < end && risword(buf_get(buf, off+1)); off++); + for (; off < end && !risword(buf_get(buf, off+1)); off++); + off++; + } + return off; +} + unsigned buf_byline(Buf* buf, unsigned pos, int count) { int move = (count < 0 ? -1 : 1); count *= move; // remove the sign if there is one diff --git a/libedit/view.c b/libedit/view.c index e3fdc7d..1d11bb7 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -230,6 +230,15 @@ void view_byrune(View* view, int move, bool extsel) { view->sync_needed = true; } +void view_byword(View* view, int move, bool extsel) { + Sel sel = view->selection; + sel.end = buf_byword(&(view->buffer), sel.end, move); + if (!extsel) sel.beg = sel.end; + sel.col = buf_getcol(&(view->buffer), sel.end); + view->selection = sel; + view->sync_needed = true; +} + void view_byline(View* view, int move, bool extsel) { Sel sel = view->selection; sel.end = buf_byline(&(view->buffer), sel.end, move); diff --git a/xedit.c b/xedit.c index 5426b20..95d8c6f 100644 --- a/xedit.c +++ b/xedit.c @@ -26,6 +26,7 @@ static void redraw(int width, int height); // UI Callbacks static void delete(void); static void del_to_bol(void); +static void del_to_bow(void); static void backspace(void); static void cursor_home(void); static void cursor_end(void); @@ -110,7 +111,7 @@ static KeyBinding Bindings[] = { /* Standard Unix Shortcuts */ { ModCtrl, 'u', del_to_bol }, - //{ KEY_CTRL_W, del_to_bow }, + { ModCtrl, 'w', del_to_bow }, { ModCtrl, 'h', backspace }, { ModCtrl, 'a', cursor_home }, { ModCtrl, 'e', cursor_end }, @@ -366,6 +367,11 @@ static void del_to_bol(void) { delete(); } +static void del_to_bow(void) { + view_byword(currview(), LEFT, true); + delete(); +} + static void backspace(void) { bool byword = x11_keymodsset(ModCtrl); view_delete(currview(), LEFT, byword); @@ -399,12 +405,18 @@ static void cursor_dn(void) { static void cursor_left(void) { bool extsel = x11_keymodsset(ModShift); - view_byrune(currview(), LEFT, extsel); + if (x11_keymodsset(ModCtrl)) + view_byword(currview(), LEFT, extsel); + else + view_byrune(currview(), LEFT, extsel); } static void cursor_right(void) { bool extsel = x11_keymodsset(ModShift); - view_byrune(currview(), RIGHT, extsel); + if (x11_keymodsset(ModCtrl)) + view_byword(currview(), RIGHT, extsel); + else + view_byrune(currview(), RIGHT, extsel); } static void page_up(void) {