]> git.mdlowis.com Git - projs/tide.git/commitdiff
Implemented page up and down, mouse chords for cut and paste, and fixed bugs in cut...
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 18 Nov 2016 18:53:58 +0000 (13:53 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 18 Nov 2016 18:53:58 +0000 (13:53 -0500)
inc/edit.h
libedit/view.c
xedit.c

index a7d3b9c1a38d8bcfd20a1a22959ea4112004102d..2e1cc5a38d59366bb5334feb9761a778dcbd1c58 100644 (file)
@@ -162,6 +162,7 @@ void view_redo(View* view);
 void view_putstr(View* view, char* str);
 char* view_getstr(View* view, Sel* sel);
 void view_scroll(View* view, int move);
+void view_scrollpage(View* view, int move);
 
 /* Command Executions
  *****************************************************************************/
index 8cdfd9c2aa8041c7cb1dc900fc2d0a97c73fa485..241e6dd88b641771d82d17e147c4ddcb46fed096 100644 (file)
@@ -313,7 +313,7 @@ char* view_getstr(View* view, Sel* range) {
     char utf[UTF_MAX] = {0};
     size_t len = 0;
     char*  str = NULL;
-    for (; sel.beg <= sel.end; sel.beg++) {
+    for (; sel.beg < sel.end; sel.beg++) {
         Rune rune = buf_get(buf, sel.beg);
         if (rune == RUNE_CRLF) {
             str = realloc(str, len + 2);
@@ -333,8 +333,17 @@ char* view_getstr(View* view, Sel* range) {
 }
 
 void view_scroll(View* view, int move) {
-    if (move < 0)
-        scroll_up(view);
-    else
-        scroll_dn(view);
+    int dir = (move < 0 ? -1 : 1);
+    move *= dir;
+    for (int i = 0; i < move; i++) {
+        if (dir < 0)
+            scroll_up(view);
+        else
+            scroll_dn(view);
+    }
+}
+
+void view_scrollpage(View* view, int move) {
+    move = (move < 0 ? -1 : 1) * view->nrows;
+    view_scroll(view, move);
 }
diff --git a/xedit.c b/xedit.c
index 7473fb1c5f86dcaa1c53097977516e22b9947747..bf62d71ab7da8ef2ba5aa6bcf243f17158a52ee5 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -94,6 +94,14 @@ static void cursor_eol(void) {
     view_eol(currview());
 }
 
+static void page_up(void) {
+    view_scrollpage(currview(), -1);
+}
+
+static void page_dn(void) {
+    view_scrollpage(currview(), +1);
+}
+
 static void change_focus(void) {
     if (Focused == TAGS) {
         if (TagWinExpanded) {
@@ -132,14 +140,17 @@ static void redo(void) {
 
 static void cut(void) {
     char* str = view_getstr(currview(), NULL);
-    cmdwrite(CopyCmd, str);
+    if (str && *str) {
+        cmdwrite(CopyCmd, str);
+        delete();
+    }
     free(str);
-    delete();
 }
 
 static void copy(void) {
+    if (str && *str)
     char* str = view_getstr(currview(), NULL);
-    cmdwrite(CopyCmd, str);
+        cmdwrite(CopyCmd, str);
     free(str);
 }
 
@@ -165,8 +176,7 @@ static void mouse_left(enum RegionId id, size_t count, size_t row, size_t col) {
 
 static void mouse_middle(enum RegionId id, size_t count, size_t row, size_t col) {
     if (MouseBtns[MOUSE_BTN_LEFT].pressed)
-        puts("cut");
-    //    cut();
+        cut();
     else
         puts("exec");
     //    view_exec(getview(id), row, col);
@@ -174,8 +184,7 @@ static void mouse_middle(enum RegionId id, size_t count, size_t row, size_t col)
 
 static void mouse_right(enum RegionId id, size_t count, size_t row, size_t col) {
     if (MouseBtns[MOUSE_BTN_LEFT].pressed)
-        puts("paste");
-    //    paste();
+        paste();
     else
         puts("find");
     //    view_find(getview(id), row, col);
@@ -242,6 +251,8 @@ static KeyBinding Insert[] = {
     { KEY_RIGHT,     cursor_right },
     { KEY_HOME,      cursor_bol   },
     { KEY_END,       cursor_eol   },
+    { KEY_PGUP,      page_up      },
+    { KEY_PGDN,      page_dn      },
     { KEY_CTRL_T,    change_focus },
     { KEY_CTRL_Q,    quit         },
     { KEY_CTRL_S,    save         },