]> git.mdlowis.com Git - projs/tide.git/commitdiff
Implemented cursor movements for beginning and end of line as well as quit keyboard...
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 17 Nov 2016 01:36:17 +0000 (20:36 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 17 Nov 2016 01:36:17 +0000 (20:36 -0500)
inc/edit.h
libedit/view.c
xedit.c

index c7e1a5f9a0fed8c19f01f8dfac79913ec4f00045..23e718478265eda81f5a38ba8faf4d1e400d0223 100644 (file)
@@ -155,6 +155,8 @@ void view_setcursor(View* view, size_t row, size_t col);
 void view_selext(View* view, size_t row, size_t col);
 void view_insert(View* view, Rune rune);
 void view_delete(View* view);
+void view_bol(View* view);
+void view_eol(View* view);
 
 //size_t view_getoff(View* view, size_t pos, size_t row, size_t col);
 //void view_getsize(View* view, size_t* nrows, size_t* ncols);
index 8877a17c4878905f9ee60b18908b30e2d4df3907..7bbcf605e16da8895e4e3bdb32855c771779b9b7 100644 (file)
@@ -271,3 +271,15 @@ void view_delete(View* view) {
     view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
     view->sync_needed = true;
 }
+
+void view_bol(View* view) {
+    view->selection.beg = view->selection.end = buf_bol(&(view->buffer), view->selection.end);
+    view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
+    view->sync_needed = true;
+}
+
+void view_eol(View* view) {
+    view->selection.beg = view->selection.end = buf_eol(&(view->buffer), view->selection.end);
+    view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
+    view->sync_needed = true;
+}
diff --git a/xedit.c b/xedit.c
index da1689a26ba6cd3516cef7b4c01b2a383e540e39..8ebcc749e4aa573074d2770b098a468fbafb738c 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -76,6 +76,14 @@ static void cursor_right(void) {
     view_byrune(currview(), +1);
 }
 
+static void cursor_bol(void) {
+    view_bol(currview());
+}
+
+static void cursor_eol(void) {
+    view_eol(currview());
+}
+
 static void change_focus(void) {
     if (Focused == TAGS) {
         if (TagWinExpanded) {
@@ -90,6 +98,49 @@ static void change_focus(void) {
     }
 }
 
+static void quit(void) {
+    static uint32_t num_clicks = 0;
+    static uint32_t prevtime = 0;
+    uint32_t now = getmillis();
+    num_clicks = (now - prevtime < 250 ? num_clicks+1 : 1);
+    prevtime = now;
+    if (!getbuf(EDIT)->modified || num_clicks >= 2)
+        exit(0);
+}
+//
+//static void write(void) {
+//    buf_save(&Buffer);
+//}
+//
+//static void undo(void) {
+//    SelBeg = SelEnd = buf_undo(&Buffer, SelEnd);
+//    TargetCol = buf_getcol(&Buffer, SelEnd);
+//}
+//
+//static void redo(void) {
+//    SelBeg = SelEnd = buf_redo(&Buffer, SelEnd);
+//    TargetCol = buf_getcol(&Buffer, SelEnd);
+//}
+//
+//static void cut(void) {
+//    char* str = buf_getstr(&Buffer, SelBeg, SelEnd);
+//    cmdwrite(CopyCmd, str);
+//    free(str);
+//    delete();
+//}
+//
+//static void copy(void) {
+//    char* str = buf_getstr(&Buffer, SelBeg, SelEnd);
+//    cmdwrite(CopyCmd, str);
+//    free(str);
+//}
+//
+//static void paste(void) {
+//    char* str = cmdread(PasteCmd);
+//    buf_putstr(&Buffer, SelBeg, SelEnd, str);
+//    free(str);
+//}
+
 /* Mouse Handling
  *****************************************************************************/
 static void mouse_left(enum RegionId id, size_t count, size_t row, size_t col) {
@@ -181,17 +232,16 @@ static KeyBinding Insert[] = {
     { KEY_DOWN,      cursor_dn     },
     { KEY_LEFT,      cursor_left   },
     { KEY_RIGHT,     cursor_right  },
-    //{ KEY_CTRL_Q,    quit          },
+    { KEY_HOME,      cursor_bol    },
+    { KEY_END,       cursor_eol    },
+    { KEY_CTRL_T,    change_focus  },
+    { KEY_CTRL_Q,    quit          },
     //{ KEY_CTRL_S,    write         },
-    { KEY_CTRL_T,    change_focus    },
     //{ KEY_CTRL_Z,    undo          },
     //{ KEY_CTRL_Y,    redo          },
     //{ KEY_CTRL_X,    cut           },
     //{ KEY_CTRL_C,    copy          },
     //{ KEY_CTRL_V,    paste         },
-    //{ KEY_HOME,      cursor_bol    },
-    //{ KEY_END,       cursor_eol    },
-    //{ KEY_BACKSPACE, backspace     },
     { 0,             NULL          }
 };
 
@@ -360,74 +410,6 @@ static char* PasteCmd[] = { "xsel", "-bo", NULL };
 
 /* Keyboard Actions
  *****************************************************************************/
-static void delete(void) {
-    if (SelEnd == buf_end(&Buffer)) return;
-    size_t n = SelEnd - SelBeg;
-    for (size_t i = 0; i < n; i++)
-        buf_del(&Buffer, SelBeg);
-    SelEnd = SelBeg;
-    TargetCol = buf_getcol(&Buffer, SelEnd);
-}
-
-static void backspace(void) {
-    if (SelBeg > 0 && SelBeg == SelEnd) SelBeg--;
-    while (SelBeg < SelEnd)
-        buf_del(&Buffer, --SelEnd);
-    TargetCol = buf_getcol(&Buffer, SelEnd);
-}
-
-static void quit(void) {
-    static uint32_t num_clicks = 0;
-    static uint32_t prevtime = 0;
-    uint32_t now = getmillis();
-    num_clicks = (now - prevtime < 250 ? num_clicks+1 : 1);
-    prevtime = now;
-    if (!Buffer.modified || num_clicks >= 2)
-        exit(0);
-}
-
-static void write(void) {
-    buf_save(&Buffer);
-}
-
-static void undo(void) {
-    SelBeg = SelEnd = buf_undo(&Buffer, SelEnd);
-    TargetCol = buf_getcol(&Buffer, SelEnd);
-}
-
-static void redo(void) {
-    SelBeg = SelEnd = buf_redo(&Buffer, SelEnd);
-    TargetCol = buf_getcol(&Buffer, SelEnd);
-}
-
-static void cut(void) {
-    char* str = buf_getstr(&Buffer, SelBeg, SelEnd);
-    cmdwrite(CopyCmd, str);
-    free(str);
-    delete();
-}
-
-static void copy(void) {
-    char* str = buf_getstr(&Buffer, SelBeg, SelEnd);
-    cmdwrite(CopyCmd, str);
-    free(str);
-}
-
-static void paste(void) {
-    char* str = cmdread(PasteCmd);
-    buf_putstr(&Buffer, SelBeg, SelEnd, str);
-    free(str);
-}
-
-static void cursor_bol(void) {
-    SelBeg = SelEnd = buf_bol(&Buffer, SelEnd);
-    TargetCol = 0;
-}
-
-static void cursor_eol(void) {
-    SelBeg = SelEnd = buf_eol(&Buffer, SelEnd);
-    TargetCol = (size_t)-1;
-}
 
 static void tagwin(void) {
     TagWinExpanded = !TagWinExpanded;