]> git.mdlowis.com Git - projs/tide.git/commitdiff
Make common action handlers shareable so xpick and term can use them
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 17 May 2017 19:54:04 +0000 (15:54 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 17 May 2017 19:54:04 +0000 (15:54 -0400)
inc/shortcuts.h [new file with mode: 0644]
xedit.c

diff --git a/inc/shortcuts.h b/inc/shortcuts.h
new file mode 100644 (file)
index 0000000..91e1e42
--- /dev/null
@@ -0,0 +1,127 @@
+static void delete(void) {
+    bool byword = x11_keymodsset(ModCtrl);
+    view_delete(win_view(FOCUSED), RIGHT, byword);
+}
+
+static void onpaste(char* text) {
+    view_putstr(win_view(FOCUSED), text);
+}
+
+static void cut(void) {
+    View* view = win_view(FOCUSED);
+    /* select the current line if no selection */
+    if (!view_selsize(view)) {
+        view_eol(view, false);
+        view_selctx(view);
+    }
+    /* now perform the cut */
+    char* str = view_getstr(view, NULL);
+    x11_sel_set(CLIPBOARD, str);
+    if (str && *str) delete();
+}
+
+static void paste(void) {
+    assert(x11_sel_get(CLIPBOARD, onpaste));
+}
+
+static void copy(void) {
+    char* str = view_getstr(win_view(FOCUSED), NULL);
+    x11_sel_set(CLIPBOARD, str);
+}
+
+static void del_to_bol(void) {
+    view_bol(win_view(FOCUSED), true);
+    if (view_selsize(win_view(FOCUSED)) > 0)
+        delete();
+}
+
+static void del_to_eol(void) {
+    view_eol(win_view(FOCUSED), true);
+    if (view_selsize(win_view(FOCUSED)) > 0)
+        delete();
+}
+
+static void del_to_bow(void) {
+    view_byword(win_view(FOCUSED), LEFT, true);
+    if (view_selsize(win_view(FOCUSED)) > 0)
+        delete();
+}
+
+static void backspace(void) {
+    bool byword = x11_keymodsset(ModCtrl);
+    view_delete(win_view(FOCUSED), LEFT, byword);
+}
+
+static void cursor_bol(void) {
+    view_bol(win_view(FOCUSED), false);
+}
+
+static void cursor_eol(void) {
+    view_eol(win_view(FOCUSED), false);
+}
+
+static void cursor_home(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl))
+        view_bof(win_view(FOCUSED), extsel);
+    else
+        view_bol(win_view(FOCUSED), extsel);
+}
+
+static void cursor_end(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl))
+        view_eof(win_view(FOCUSED), extsel);
+    else
+        view_eol(win_view(FOCUSED), extsel);
+}
+
+static void cursor_up(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    view_byline(win_view(FOCUSED), UP, extsel);
+}
+
+static void cursor_dn(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    view_byline(win_view(FOCUSED), DOWN, extsel);
+}
+
+static void cursor_left(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl))
+        view_byword(win_view(FOCUSED), LEFT, extsel);
+    else
+        view_byrune(win_view(FOCUSED), LEFT, extsel);
+}
+
+static void cursor_right(void) {
+    bool extsel = x11_keymodsset(ModShift);
+    if (x11_keymodsset(ModCtrl))
+        view_byword(win_view(FOCUSED), RIGHT, extsel);
+    else
+        view_byrune(win_view(FOCUSED), RIGHT, extsel);
+}
+
+static void page_up(void) {
+    view_scrollpage(win_view(FOCUSED), UP);
+}
+
+static void page_dn(void) {
+    view_scrollpage(win_view(FOCUSED), DOWN);
+}
+
+static void select_prev(void) {
+    view_selprev(win_view(FOCUSED));
+}
+
+static void change_focus(void) {
+    win_setregion(win_getregion() == TAGS ? EDIT : TAGS);
+}
+
+static void undo(void) {
+    view_undo(win_view(FOCUSED));
+}
+
+static void redo(void) {
+    view_redo(win_view(FOCUSED));
+}
diff --git a/xedit.c b/xedit.c
index 25701fd63f609f2a006720942b6808c5840a8c7c..234488ddf4126a01f3163928bbb7a12b3ad91688 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -4,6 +4,7 @@
 #include <edit.h>
 #include <ctype.h>
 #include <win.h>
+#include <shortcuts.h>
 
 typedef struct {
     char* tag;
@@ -105,37 +106,6 @@ static void exec(char* cmd) {
 
 /* Action Callbacks
  ******************************************************************************/
-static void delete(void) {
-    bool byword = x11_keymodsset(ModCtrl);
-    view_delete(win_view(FOCUSED), RIGHT, byword);
-}
-
-static void onpaste(char* text) {
-    view_putstr(win_view(FOCUSED), text);
-}
-
-static void cut(void) {
-    View* view = win_view(FOCUSED);
-    /* select the current line if no selection */
-    if (!view_selsize(view)) {
-        view_eol(view, false);
-        view_selctx(view);
-    }
-    /* now perform the cut */
-    char* str = view_getstr(view, NULL);
-    x11_sel_set(CLIPBOARD, str);
-    if (str && *str) delete();
-}
-
-static void paste(void) {
-    assert(x11_sel_get(CLIPBOARD, onpaste));
-}
-
-static void copy(void) {
-    char* str = view_getstr(win_view(FOCUSED), NULL);
-    x11_sel_set(CLIPBOARD, str);
-}
-
 static void quit(void) {
     static uint64_t before = 0;
     uint64_t now = getmillis();
@@ -197,103 +167,6 @@ void onmouseright(WinRegion id, size_t count, size_t row, size_t col) {
 
 /* Keyboard Handling
  ******************************************************************************/
-static void del_to_bol(void) {
-    view_bol(win_view(FOCUSED), true);
-    if (view_selsize(win_view(FOCUSED)) > 0)
-        delete();
-}
-
-static void del_to_eol(void) {
-    view_eol(win_view(FOCUSED), true);
-    if (view_selsize(win_view(FOCUSED)) > 0)
-        delete();
-}
-
-static void del_to_bow(void) {
-    view_byword(win_view(FOCUSED), LEFT, true);
-    if (view_selsize(win_view(FOCUSED)) > 0)
-        delete();
-}
-
-static void backspace(void) {
-    bool byword = x11_keymodsset(ModCtrl);
-    view_delete(win_view(FOCUSED), LEFT, byword);
-}
-
-static void cursor_bol(void) {
-    view_bol(win_view(FOCUSED), false);
-}
-
-static void cursor_eol(void) {
-    view_eol(win_view(FOCUSED), false);
-}
-
-static void cursor_home(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_bof(win_view(FOCUSED), extsel);
-    else
-        view_bol(win_view(FOCUSED), extsel);
-}
-
-static void cursor_end(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_eof(win_view(FOCUSED), extsel);
-    else
-        view_eol(win_view(FOCUSED), extsel);
-}
-
-static void cursor_up(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    view_byline(win_view(FOCUSED), UP, extsel);
-}
-
-static void cursor_dn(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    view_byline(win_view(FOCUSED), DOWN, extsel);
-}
-
-static void cursor_left(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_byword(win_view(FOCUSED), LEFT, extsel);
-    else
-        view_byrune(win_view(FOCUSED), LEFT, extsel);
-}
-
-static void cursor_right(void) {
-    bool extsel = x11_keymodsset(ModShift);
-    if (x11_keymodsset(ModCtrl))
-        view_byword(win_view(FOCUSED), RIGHT, extsel);
-    else
-        view_byrune(win_view(FOCUSED), RIGHT, extsel);
-}
-
-static void page_up(void) {
-    view_scrollpage(win_view(FOCUSED), UP);
-}
-
-static void page_dn(void) {
-    view_scrollpage(win_view(FOCUSED), DOWN);
-}
-
-static void select_prev(void) {
-    view_selprev(win_view(FOCUSED));
-}
-
-static void change_focus(void) {
-    win_setregion(win_getregion() == TAGS ? EDIT : TAGS);
-}
-
-static void undo(void) {
-    view_undo(win_view(FOCUSED));
-}
-
-static void redo(void) {
-    view_redo(win_view(FOCUSED));
-}
-
 static void saveas(char* arg) {
     if (arg) {
         char* path = win_buf(EDIT)->path;