]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 26 Mar 2018 01:59:56 +0000 (21:59 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 26 Mar 2018 01:59:56 +0000 (21:59 -0400)
inc/edit.h
lib/view.c
lib/x11.c
tide.c

index fadd6d0e9a87965aeecebe6f18b9afab809a893b..08cfa11e0f4b10a768dd3cadf394747549f48505 100644 (file)
@@ -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);
index d10946836df25cde1fad0ba978d4f859b0f293f4..beeceba004a7771291c0c240a54299e7a14f1c9d 100644 (file)
@@ -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)
index e84c284e26073c226f8c31436c7734fe2745ae7e..eac2b88357ca97a9a9d20de6a5180dcc3c20a5df 100644 (file)
--- 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 47d6bf65cb2344af378f2240589d6af4b051fdfa..c7cf3008aa58135048b99bc80adb791eeef8b421 100644 (file)
--- 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 */