From 4502374dcf720a5cc1d5c5a4aa86acf5c2c24e7d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 25 Mar 2018 21:59:56 -0400 Subject: [PATCH] minor refactoring --- inc/edit.h | 3 +-- lib/view.c | 18 +++++------------- lib/x11.c | 15 +-------------- tide.c | 9 +++------ 4 files changed, 10 insertions(+), 35 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index fadd6d0..08cfa11 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -186,8 +186,7 @@ void view_setln(View* view, size_t line); void view_indent(View* view, int dir); size_t view_selsize(View* view); void view_selprev(View* view); -void view_setcursor(View* view, size_t row, size_t col); -void view_selext(View* view, size_t row, size_t col); +void view_setcursor(View* view, size_t row, size_t col, bool extsel); void view_selextend(View* view, size_t row, size_t col); void view_selword(View* view, size_t row, size_t col); void view_select(View* view, size_t row, size_t col); diff --git a/lib/view.c b/lib/view.c index d109468..beeceba 100644 --- a/lib/view.c +++ b/lib/view.c @@ -107,35 +107,26 @@ Row* view_getrow(View* view, size_t row) { void view_byrune(View* view, int move, bool extsel) { move_selection(view, extsel, &(view->selection), move, buf_byrune); - view->sync_needed = true; } void view_byword(View* view, int move, bool extsel) { move_selection(view, extsel, &(view->selection), move, buf_byword); - view->sync_needed = true; } void view_byline(View* view, int move, bool extsel) { move_selection(view, extsel, &(view->selection), move, buf_byline); - view->sync_needed = true; -} - -void view_setcursor(View* view, size_t row, size_t col) { - size_t off = getoffset(view, row, col); - if (off != SIZE_MAX) - view_jumpto(view, false, off); } -void view_selext(View* view, size_t row, size_t col) { +void view_setcursor(View* view, size_t row, size_t col, bool extsel) { size_t off = getoffset(view, row, col); if (off != SIZE_MAX) - view_jumpto(view, true, off); + view_jumpto(view, extsel, off); } void view_selword(View* view, size_t row, size_t col) { buf_loglock(&(view->buffer)); if (row != SIZE_MAX && col != SIZE_MAX) - view_setcursor(view, row, col); + view_setcursor(view, row, col, false); Sel sel = view->selection; buf_getword(&(view->buffer), risbigword, &(sel)); sel.end++; @@ -155,7 +146,7 @@ void view_selprev(View* view) { void view_select(View* view, size_t row, size_t col) { buf_loglock(&(view->buffer)); - view_setcursor(view, row, col); + view_setcursor(view, row, col, false); Sel sel = view->selection; select_context(view, risword, &sel); view->selection = sel; @@ -421,6 +412,7 @@ void view_scrollto(View* view, size_t csr) { } static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t bything) { + view->sync_needed = true; if (num_selected(*sel) && !extsel) { selswap(sel); if (move == RIGHT || move == DOWN) diff --git a/lib/x11.c b/lib/x11.c index e84c284..eac2b88 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -391,12 +391,6 @@ void win_init(void (*errfn)(char*)) { Regions[EDIT].clrcsr = Colors[ClrEditCsr]; } -void win_load(char* path) { - View* view = win_view(EDIT); - view_init(view, path, view->buffer.errfn); - path = view->buffer.path; -} - void win_save(char* path) { View* view = win_view(EDIT); if (!path) path = view->buffer.path; @@ -408,14 +402,7 @@ void win_save(char* path) { } void win_loop(void) { - /* simulate an initial resize and map the window */ - XConfigureEvent ce; - ce.type = ConfigureNotify; - ce.width = X.width; - ce.height = X.height; - XSendEvent(X.display, X.self, False, StructureNotifyMask, (XEvent *)&ce); XMapWindow(X.display, X.self); - while (Running) { bool pending = job_poll(ConnectionNumber(X.display), Timeout); int nevents = XEventsQueued(X.display, QueuedAfterFlush); @@ -643,7 +630,7 @@ static void onmousedrag(int state, int x, int y) { size_t row = (y-Regions[Focused].y) / x11_font_height(CurrFont); size_t col = (x-Regions[Focused].x) / x11_font_width(CurrFont); if (win_btnpressed(MouseLeft)) - view_selext(win_view(Focused), row, col); + view_setcursor(win_view(Focused), row, col, true); } static void onmousebtn(int btn, bool pressed, int x, int y) { diff --git a/tide.c b/tide.c index 47d6bf6..c7cf300 100644 --- a/tide.c +++ b/tide.c @@ -370,10 +370,7 @@ void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) { before = now; if (count == 1) { - if (x11_keymodsset(ModShift)) - view_selext(win_view(id), row, col); - else - view_setcursor(win_view(id), row, col); + view_setcursor(win_view(id), row, col, x11_keymodsset(ModShift)); } else if (count == 2) { view_select(win_view(id), row, col); } else if (count == 3) { @@ -679,10 +676,10 @@ void edit_relative(char* path) { else strconcat(currpath, fname, 0); chdir(currdir); - win_load(currpath); + view_init(win_view(EDIT), currpath, ondiagmsg); } else { chdir(origdir); - win_load(path); + view_init(win_view(EDIT), path, ondiagmsg); } /* cleanup */ -- 2.54.0