From 200aa6b03565e3dd42653c6430eb3913ce173ce0 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 18 Nov 2016 13:53:58 -0500 Subject: [PATCH] Implemented page up and down, mouse chords for cut and paste, and fixed bugs in cut and copy --- inc/edit.h | 1 + libedit/view.c | 19 ++++++++++++++----- xedit.c | 25 ++++++++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index a7d3b9c..2e1cc5a 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -162,6 +162,7 @@ void view_redo(View* view); void view_putstr(View* view, char* str); char* view_getstr(View* view, Sel* sel); void view_scroll(View* view, int move); +void view_scrollpage(View* view, int move); /* Command Executions *****************************************************************************/ diff --git a/libedit/view.c b/libedit/view.c index 8cdfd9c..241e6dd 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -313,7 +313,7 @@ char* view_getstr(View* view, Sel* range) { char utf[UTF_MAX] = {0}; size_t len = 0; char* str = NULL; - for (; sel.beg <= sel.end; sel.beg++) { + for (; sel.beg < sel.end; sel.beg++) { Rune rune = buf_get(buf, sel.beg); if (rune == RUNE_CRLF) { str = realloc(str, len + 2); @@ -333,8 +333,17 @@ char* view_getstr(View* view, Sel* range) { } void view_scroll(View* view, int move) { - if (move < 0) - scroll_up(view); - else - scroll_dn(view); + int dir = (move < 0 ? -1 : 1); + move *= dir; + for (int i = 0; i < move; i++) { + if (dir < 0) + scroll_up(view); + else + scroll_dn(view); + } +} + +void view_scrollpage(View* view, int move) { + move = (move < 0 ? -1 : 1) * view->nrows; + view_scroll(view, move); } diff --git a/xedit.c b/xedit.c index 7473fb1..bf62d71 100644 --- a/xedit.c +++ b/xedit.c @@ -94,6 +94,14 @@ static void cursor_eol(void) { view_eol(currview()); } +static void page_up(void) { + view_scrollpage(currview(), -1); +} + +static void page_dn(void) { + view_scrollpage(currview(), +1); +} + static void change_focus(void) { if (Focused == TAGS) { if (TagWinExpanded) { @@ -132,14 +140,17 @@ static void redo(void) { static void cut(void) { char* str = view_getstr(currview(), NULL); - cmdwrite(CopyCmd, str); + if (str && *str) { + cmdwrite(CopyCmd, str); + delete(); + } free(str); - delete(); } static void copy(void) { + if (str && *str) char* str = view_getstr(currview(), NULL); - cmdwrite(CopyCmd, str); + cmdwrite(CopyCmd, str); free(str); } @@ -165,8 +176,7 @@ static void mouse_left(enum RegionId id, size_t count, size_t row, size_t col) { static void mouse_middle(enum RegionId id, size_t count, size_t row, size_t col) { if (MouseBtns[MOUSE_BTN_LEFT].pressed) - puts("cut"); - // cut(); + cut(); else puts("exec"); // view_exec(getview(id), row, col); @@ -174,8 +184,7 @@ static void mouse_middle(enum RegionId id, size_t count, size_t row, size_t col) static void mouse_right(enum RegionId id, size_t count, size_t row, size_t col) { if (MouseBtns[MOUSE_BTN_LEFT].pressed) - puts("paste"); - // paste(); + paste(); else puts("find"); // view_find(getview(id), row, col); @@ -242,6 +251,8 @@ static KeyBinding Insert[] = { { KEY_RIGHT, cursor_right }, { KEY_HOME, cursor_bol }, { KEY_END, cursor_eol }, + { KEY_PGUP, page_up }, + { KEY_PGDN, page_dn }, { KEY_CTRL_T, change_focus }, { KEY_CTRL_Q, quit }, { KEY_CTRL_S, save }, -- 2.49.0