From 21ab3df6b094b0ea51f0d18bc946b2457bf66ef1 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 3 Apr 2018 13:23:57 -0400 Subject: [PATCH] fixed some abstraction leaks in view --- inc/edit.h | 3 +++ lib/view.c | 10 ++++++++++ lib/x11.c | 5 ----- tide.c | 21 +++++---------------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index b98a1c8..231c6fa 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -128,6 +128,7 @@ void view_redo(View* view); void view_putstr(View* view, char* str); char* view_getstr(View* view, Sel* sel); char* view_getcmd(View* view); +char* view_getword(View* view); char* view_getctx(View* view); void view_selctx(View* view); void view_scroll(View* view, int move); @@ -142,6 +143,8 @@ void view_select(View* view, size_t row, size_t col); void view_jumpto(View* view, bool extsel, size_t off); void view_scrollto(View* view, size_t csr); Rune view_getrune(View* view); +void view_selectall(View* view); +void view_selectobj(View* view, bool (*istype)(Rune)); /* Command Executions *****************************************************************************/ diff --git a/lib/view.c b/lib/view.c index 6c50d68..6f62db7 100644 --- a/lib/view.c +++ b/lib/view.c @@ -282,6 +282,16 @@ void view_scrollto(View* view, size_t csr) { } } +void view_selectall(View* view) { + view->selection = (Sel){ .beg = 0, .end = buf_end(&(view->buffer)) }; + view->sync_needed = true; +} + +void view_selectobj(View* view, bool (*istype)(Rune)) { + buf_getword(&(view->buffer), istype, &(view->selection)); + view->sync_needed = true; +} + static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t bything) { view->sync_needed = true; if (num_selected(*sel) && !extsel) { diff --git a/lib/x11.c b/lib/x11.c index fd7aa20..716d5e1 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -137,9 +137,6 @@ void win_init(KeyBinding* bindings) { Keys = bindings; CurrFont = x11_font_load(FontString); View* view = win_view(TAGS); - view->buffer.gapstart = view->buffer.bufstart; - view->buffer.gapend = view->buffer.bufend; - view->selection = (Sel){0,0,0}; view_putstr(view, TagString); view_selprev(view); // clear the selection buf_logclear(&(view->buffer)); @@ -191,8 +188,6 @@ void win_quit(void) { uint64_t now = getmillis(); if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime) exit(0); -// else -// view_append(win_view(TAGS), "File is modified."); before = now; } diff --git a/tide.c b/tide.c index f732aa3..6e3f638 100644 --- a/tide.c +++ b/tide.c @@ -40,9 +40,7 @@ static void select_line(char* arg) { } static void select_all(char* arg) { - View* view = win_view(FOCUSED); - view_jumpto(view, false, buf_end(&(view->buffer))); - view->selection.beg = 0; + view_selectall(win_view(FOCUSED)); } static void join_lines(char* arg) { @@ -73,11 +71,7 @@ void cut(char* arg) { /* now perform the cut */ char* str = view_getstr(view, NULL); x11_sel_set(CLIPBOARD, str); - if (str && *str) { - delete(arg); - if (view->selection.end == buf_end(&(view->buffer))) - view_delete(view, LEFT, false); - } + if (str && *str) delete(arg); } void paste(char* arg) { @@ -241,7 +235,7 @@ static void cmd_exec(char* cmd) { /* get the selection that the command will operate on */ if (op && op != '<' && op != '!' && 0 == view_selsize(win_view(EDIT))) - win_view(EDIT)->selection = (Sel){ .beg = 0, .end = buf_end(win_buf(EDIT)) }; + view_selectall(win_view(EDIT)); char* input = view_getstr(win_view(EDIT), NULL); size_t len = (input ? strlen(input) : 0); View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); @@ -345,8 +339,8 @@ static void pick_ctag(char* arg) { static void complete(char* arg) { View* view = win_view(FOCUSED); - buf_getword(&(view->buffer), risword, &(view->selection)); - view->selection.end = buf_byrune(&(view->buffer), view->selection.end, RIGHT); + view_selectobj(view, risword); + view_byrune(view, RIGHT, true); cmd_execwitharg(CMD_COMPLETE, view_getstr(view, NULL)); } @@ -390,11 +384,6 @@ static void newline(char* arg) { if (x11_keymodsset(ModShift)) { view_byline(view, UP, false); view_bol(view, false); - if (view->selection.end == 0) { - view_insert(view, true, '\n'); - view->selection = (Sel){0,0,0}; - return; - } } view_eol(view, false); view_insert(view, true, '\n'); -- 2.54.0