From: Michael D. Lowis Date: Wed, 23 Nov 2016 16:12:38 +0000 (-0500) Subject: Added escape shortcut to select the last inserted text X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=48db05a21daa603a6a52330a448053d3638515aa;p=projs%2Ftide.git Added escape shortcut to select the last inserted text --- diff --git a/inc/edit.h b/inc/edit.h index 848c8eb..bf7b8a9 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -75,8 +75,8 @@ unsigned buf_byrune(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); -char* buf_getstr(Buf* buf, unsigned beg, unsigned end); -unsigned buf_putstr(Buf* buf, unsigned beg, unsigned end, char* str); +void buf_lastins(Buf* buf, size_t* beg, size_t* end); +void buf_loglock(Buf* buf); /* void buf_load(Buf* buf, char* path); @@ -156,6 +156,7 @@ void view_byline(View* view, int move); void view_setcursor(View* view, size_t row, size_t col); void view_selext(View* view, size_t row, size_t col); void view_selword(View* view, size_t row, size_t col); +void view_selprev(View* view); void view_select(View* view, size_t row, size_t col); char* view_fetch(View* view, size_t row, size_t col); void view_find(View* view, size_t row, size_t col); diff --git a/libedit/buf.c b/libedit/buf.c index c87b467..52e240a 100644 --- a/libedit/buf.c +++ b/libedit/buf.c @@ -404,3 +404,21 @@ unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col) { } return curr; } + +void buf_lastins(Buf* buf, size_t* beg, size_t* end) { + Log* log = buf->undo; + while (log) { + if (log->insert) + break; + log = log->next; + } + if (log) { + *beg = log->data.ins.beg; + *end = log->data.ins.end; + } +} + +void buf_loglock(Buf* buf) { + if (buf->undo) + buf->undo->locked = true; +} diff --git a/libedit/view.c b/libedit/view.c index 1fcf318..f35634c 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -297,6 +297,12 @@ void view_selword(View* view, size_t row, size_t col) { view->selection = sel; } +void view_selprev(View* view) { + Sel sel = view->selection; + buf_lastins(&(view->buffer), &sel.beg, &sel.end); + view->selection = sel; +} + void view_select(View* view, size_t row, size_t col) { view_setcursor(view, row, col); Sel sel = view->selection; @@ -406,12 +412,14 @@ void view_redo(View* view) { } void view_putstr(View* view, char* str) { + buf_loglock(&(view->buffer)); while (*str) { Rune rune = 0; size_t length = 0; while (!utf8decode(&rune, &length, *str++)); view_insert(view, rune); } + buf_loglock(&(view->buffer)); } char* view_getstr(View* view, Sel* range) { diff --git a/xedit b/xedit deleted file mode 100755 index 41b247d..0000000 Binary files a/xedit and /dev/null differ diff --git a/xedit.c b/xedit.c index d18dbd2..f06d906 100644 --- a/xedit.c +++ b/xedit.c @@ -34,6 +34,7 @@ static void cursor_bol(void); static void cursor_eol(void); static void page_up(void); static void page_dn(void); +static void select_prev(void); static void change_focus(void); static void quit(void); static void save(void); @@ -101,6 +102,7 @@ static KeyBinding Insert[] = { { KEY_END, cursor_eol }, { KEY_PGUP, page_up }, { KEY_PGDN, page_dn }, + { KEY_ESCAPE, select_prev }, { KEY_CTRL_T, change_focus }, { KEY_CTRL_Q, quit }, { KEY_CTRL_S, save }, @@ -359,6 +361,10 @@ static void page_dn(void) { view_scrollpage(currview(), +1); } +static void select_prev(void) { + view_selprev(currview()); +} + static void change_focus(void) { Focused = (Focused == TAGS ? EDIT : TAGS); }