]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented navigation and deletion by word
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 2 Dec 2016 01:49:32 +0000 (20:49 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 2 Dec 2016 01:49:32 +0000 (20:49 -0500)
inc/edit.h
libedit/buf.c
libedit/view.c
xedit.c

index a124935e1976d71f1706cc25e861d198d86ea747..2bd49713906a978a34cad025878cb63e89cbb525 100644 (file)
@@ -73,40 +73,13 @@ void buf_find(Buf* buf, size_t* beg, size_t* end);
 void buf_findstr(Buf* buf, char* str, size_t* beg, size_t* end);
 unsigned buf_end(Buf* buf);
 unsigned buf_byrune(Buf* buf, unsigned pos, int count);
+unsigned buf_byword(Buf* buf, unsigned pos, int count);
 unsigned buf_byline(Buf* buf, unsigned pos, int count);
 unsigned buf_getcol(Buf* buf, unsigned pos);
 unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col);
 void buf_lastins(Buf* buf, size_t* beg, size_t* end);
 void buf_loglock(Buf* buf);
 
-/*
-void buf_load(Buf* buf, char* path);
-void buf_save(Buf* buf);
-void buf_init(Buf* buf);
-void buf_ins(Buf* buf, Sel csr, Rune);
-void buf_del(Buf* buf, Sel csr);
-Sel buf_undo(Buf* buf, Sel csr);
-Sel buf_redo(Buf* buf, Sel csr);
-Rune buf_get(Buf* buf, Sel csr);
-void buf_setlocked(Buf* buf, bool locked);
-bool buf_locked(Buf* buf);
-bool buf_iseol(Buf* buf, Sel csr);
-Sel buf_bol(Buf* buf, Sel csr);
-Sel buf_eol(Buf* buf, Sel csr);
-Sel buf_bow(Buf* buf, Sel csr);
-Sel buf_eow(Buf* buf, Sel csr);
-Sel buf_lscan(Buf* buf, Sel csr, Rune r);
-Sel buf_rscan(Buf* buf, Sel csr, Rune r);
-Sel buf_find(Buf* buf, Sel csr);
-Sel buf_end(Buf* buf);
-Sel buf_byrune(Buf* buf, Sel csr, int count);
-Sel buf_byline(Buf* buf, Sel csr, int count);
-Sel buf_getcol(Buf* buf, Sel csr);
-Sel buf_setcol(Buf* buf, Sel csr, unsigned col);
-char* buf_getstr(Buf* buf, Sel csr);
-Sel buf_putstr(Buf* buf, Sel csr, char* str);
-*/
-
 /* Charset Handling
  *****************************************************************************/
 enum {
@@ -160,6 +133,7 @@ void view_resize(View* view, size_t nrows, size_t ncols);
 void view_update(View* view, size_t* csrx, size_t* csry);
 Row* view_getrow(View* view, size_t row);
 void view_byrune(View* view, int move, bool extsel);
+void view_byword(View* view, int move, bool extsel);
 void view_byline(View* view, int move, bool extsel);
 void view_setcursor(View* view, size_t row, size_t col);
 void view_selext(View* view, size_t row, size_t col);
index 7cf20a72335204570f354556a051db44fb5f1e7d..658cd198a7881b2050f7a7eb14d3bba5d113efeb 100644 (file)
@@ -361,6 +361,20 @@ unsigned buf_byrune(Buf* buf, unsigned pos, int count) {
     return pos;
 }
 
+unsigned buf_byword(Buf* buf, unsigned off, int count) {
+    int move = (count < 0 ? -1 : 1);
+    unsigned end = buf_end(buf);
+    if (move < 0) {
+        for (; off > 0 && !risword(buf_get(buf, off-1)); off--);
+        for (; off > 0 && risword(buf_get(buf, off-1)); off--);
+    } else {
+        for (; off < end && risword(buf_get(buf, off+1)); off++);
+        for (; off < end && !risword(buf_get(buf, off+1)); off++);
+        off++;
+    }
+    return off;
+}
+
 unsigned buf_byline(Buf* buf, unsigned pos, int count) {
     int move = (count < 0 ? -1 : 1);
     count *= move; // remove the sign if there is one
index e3fdc7df1d03f069fd80308f2a0683577637977f..1d11bb795420e72b76abd6cccf151e66a9964d1c 100644 (file)
@@ -230,6 +230,15 @@ void view_byrune(View* view, int move, bool extsel) {
     view->sync_needed = true;
 }
 
+void view_byword(View* view, int move, bool extsel) {
+    Sel sel = view->selection;
+    sel.end = buf_byword(&(view->buffer), sel.end, move);
+    if (!extsel) sel.beg = sel.end;
+    sel.col = buf_getcol(&(view->buffer), sel.end);
+    view->selection = sel;
+    view->sync_needed = true;
+}
+
 void view_byline(View* view, int move, bool extsel) {
     Sel sel = view->selection;
     sel.end = buf_byline(&(view->buffer), sel.end, move);
diff --git a/xedit.c b/xedit.c
index 5426b2016b92e0a8386cbf4a59adbdbaad9d6dbf..95d8c6f8f26e4ca7b6b172bf6b5519afe8693e2c 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -26,6 +26,7 @@ static void redraw(int width, int height);
 // UI Callbacks
 static void delete(void);
 static void del_to_bol(void);
+static void del_to_bow(void);
 static void backspace(void);
 static void cursor_home(void);
 static void cursor_end(void);
@@ -110,7 +111,7 @@ static KeyBinding Bindings[] = {
 
     /* Standard Unix Shortcuts */
     { ModCtrl, 'u', del_to_bol  },
-    //{ KEY_CTRL_W,    del_to_bow   },
+    { ModCtrl, 'w', del_to_bow  },
     { ModCtrl, 'h', backspace   },
     { ModCtrl, 'a', cursor_home },
     { ModCtrl, 'e', cursor_end  },
@@ -366,6 +367,11 @@ static void del_to_bol(void) {
     delete();
 }
 
+static void del_to_bow(void) {
+    view_byword(currview(), LEFT, true);
+    delete();
+}
+
 static void backspace(void) {
     bool byword = x11_keymodsset(ModCtrl);
     view_delete(currview(), LEFT, byword);
@@ -399,12 +405,18 @@ static void cursor_dn(void) {
 
 static void cursor_left(void) {
     bool extsel = x11_keymodsset(ModShift);
-    view_byrune(currview(), LEFT, extsel);
+    if (x11_keymodsset(ModCtrl))
+        view_byword(currview(), LEFT, extsel);
+    else
+        view_byrune(currview(), LEFT, extsel);
 }
 
 static void cursor_right(void) {
     bool extsel = x11_keymodsset(ModShift);
-    view_byrune(currview(), RIGHT, extsel);
+    if (x11_keymodsset(ModCtrl))
+        view_byword(currview(), RIGHT, extsel);
+    else
+        view_byrune(currview(), RIGHT, extsel);
 }
 
 static void page_up(void) {