]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactored cursor movements
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 30 Mar 2018 03:24:24 +0000 (23:24 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 30 Mar 2018 03:24:24 +0000 (23:24 -0400)
inc/x11.h
lib/x11.c
tide.c

index 5e23f6aefb1474468679d1375c71a67c2887abed..979c05b0e38be54d68b4580da4a153388d0238f0 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -107,17 +107,13 @@ enum {
 void x11_init(void);
 bool x11_keymodsset(int mask);
 void x11_window(char* name);
-
 XFont x11_font_load(char* name);
 size_t x11_font_height(XFont fnt);
 size_t x11_font_width(XFont fnt);
 size_t x11_font_descent(XFont fnt);
 void x11_font_getglyph(XFont font, XGlyphSpec* spec, uint32_t rune);
 size_t x11_font_getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, XFont font, int x, int y);
-
 void x11_draw_rect(int color, int x, int y, int width, int height);
 void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol);
-
 bool x11_sel_get(int selid, void(*cbfn)(char*));
 bool x11_sel_set(int selid, char* str);
-
index d8302b992826693609226ba5cb10f4036606900d..4d37618d701921e296e286873e7a3ffeb8cb8162 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -417,8 +417,6 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol)
     XftColorFree(X.display, X.visual, X.colormap, &fgc);
 }
 
-/******************************************************************************/
-
 void x11_draw_rect(int color, int x, int y, int width, int height) {
     XftColor clr;
     xftcolor(&clr, color);
diff --git a/tide.c b/tide.c
index 325ec79c1eba9513b9e58f0066bdff9e4bce770f..a7b9361587ea968c3dad7979f836aa41321979f8 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -124,69 +124,64 @@ static void cursor_eol(char* arg) {
     view_eol(win_view(FOCUSED), false);
 }
 
-static void move_line_up(char* arg) {
-    if (!view_selsize(win_view(FOCUSED)))
-        select_line(arg);
-    cut(arg);
-    view_byline(win_view(FOCUSED), UP, false);
-    paste(arg);
+/******************************************************************************/
+
+static void cursor_mvlr(int dir) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl))
+        view_byword(win_view(FOCUSED), dir, extsel);
+    else
+        view_byrune(win_view(FOCUSED), dir, extsel);
 }
 
-static void move_line_dn(char* arg) {
-    if (!view_selsize(win_view(FOCUSED)))
-        select_line(arg);
-    cut(arg);
-    cursor_eol(arg);
-    view_byrune(win_view(FOCUSED), RIGHT, false);
-    paste(arg);
+static void cursor_mvupdn(int dir) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl)) {
+        if (!view_selsize(win_view(FOCUSED)))
+            select_line(0);
+        cut(0);
+        view_byline(win_view(FOCUSED), dir, false);
+        paste(0);
+    } else {
+        view_byline(win_view(FOCUSED), dir, extsel);
+    }
 }
 
-static void cursor_home(char* arg) {
+static void cursor_home_end(
+    void (*docfn)(View*, bool),
+    void (*linefn)(View*, bool)
+) {
     bool extsel = x11_keymodsset(ModShift);
     if (x11_keymodsset(ModCtrl))
-        view_bof(win_view(FOCUSED), extsel);
+        docfn(win_view(FOCUSED), extsel);
     else
-        view_bol(win_view(FOCUSED), extsel);
+        linefn(win_view(FOCUSED), extsel);
+}
+
+/******************************************************************************/
+
+static void cursor_home(char* arg) {
+    cursor_home_end(view_bof, view_bol);
 }
 
 static void cursor_end(char* arg) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_eof(win_view(FOCUSED), extsel);
-    else
-        view_eol(win_view(FOCUSED), extsel);
+    cursor_home_end(view_eof, view_eol);
 }
 
 static void cursor_up(char* arg) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        move_line_up(arg);
-    else
-        view_byline(win_view(FOCUSED), UP, extsel);
+    cursor_mvupdn(UP);
 }
 
 static void cursor_dn(char* arg) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        move_line_dn(arg);
-    else
-        view_byline(win_view(FOCUSED), DOWN, extsel);
+    cursor_mvupdn(DOWN);
 }
 
 static void cursor_left(char* arg) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_byword(win_view(FOCUSED), LEFT, extsel);
-    else
-        view_byrune(win_view(FOCUSED), LEFT, extsel);
+    cursor_mvlr(LEFT);
 }
 
 static void cursor_right(char* arg) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_byword(win_view(FOCUSED), RIGHT, extsel);
-    else
-        view_byrune(win_view(FOCUSED), RIGHT, extsel);
+    cursor_mvlr(RIGHT);
 }
 
 static void page_up(char* arg) {