]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added logic to show and hide the tag buffer while keeping the selection visible in...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 15 Nov 2016 01:01:05 +0000 (20:01 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 15 Nov 2016 01:01:05 +0000 (20:01 -0500)
config.mk
inc/edit.h
libedit/view.c
xedit.c

index fc63cfeabffaa47c7179e962dd4d6fbf1046ff5e..b9996f606944e2f6cf85416100c5e09e4cfd7cde 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -2,7 +2,7 @@
 
 # Compiler Setup
 CC = c99
-CFLAGS = -Os $(INCS)
+CFLAGS = -O0 $(INCS)
 
 # Linker Setup
 LD = $(CC)
index 2f42f6c957a302926d9db18baef85c1fa4a881f6..d684a3f3285092319552ef810821ac75ae38d4c7 100644 (file)
@@ -156,6 +156,7 @@ Row* view_getrow(View* view, size_t row);
 void view_byrune(View* view, int move);
 void view_byline(View* view, int move);
 void view_setcursor(View* view, size_t row, size_t col);
+void view_insert(View* view, Rune rune);
 
 //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);
@@ -255,4 +256,4 @@ enum {
         0xff2aa198,   \
         0xff859900    \
     }
-#define DEFAULT_TAGS "Quit Save"
+#define DEFAULT_TAGS "Quit Save Cut Copy Paste | Find \n"
index 9ddd0b79a32b99295b8ea46e42f798abd96de706..b4a1d8eb954c71a11b87176e21dd69e33fbbb0e4 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
+#include <ctype.h>
 
 #define ATTR_NORMAL   (CLR_BASE03 << 8 | CLR_BASE0)
 #define ATTR_SELECTED (CLR_BASE0  << 8 | CLR_BASE03)
@@ -122,9 +123,11 @@ void view_init(View* view, char* file) {
 }
 
 void view_resize(View* view, size_t nrows, size_t ncols) {
+    size_t off = 0;
     if (view->nrows == nrows && view->ncols == ncols)  return;
     /* free the old row data */
     if (view->nrows) {
+        off = view->rows[0]->off;
         for (unsigned i = 0; i < view->nrows; i++)
             free(view->rows[i]);
         free(view->rows);
@@ -134,16 +137,17 @@ void view_resize(View* view, size_t nrows, size_t ncols) {
     for (unsigned i = 0; i < nrows; i++)
         view->rows[i] = calloc(1, sizeof(Row) + (ncols * sizeof(UGlyph)));
     /* update dimensions */
+    view->rows[0]->off = off;
     view->nrows = nrows;
     view->ncols = ncols;
     /* populate the screen buffer */
     reflow(view);
+    sync_view(view, view->selection.end);
 }
 
 void view_update(View* view, size_t* csrx, size_t* csry) {
     size_t csr = view->selection.end;
     /* scroll the view and reflow the screen lines */
-    sync_view(view, csr);
     reflow(view);
     /* find the cursor on the new screen */
     for (size_t y = 0; y < view->nrows; y++) {
@@ -172,6 +176,7 @@ void view_byrune(View* view, int move) {
     sel.beg = sel.end = buf_byrune(&(view->buffer), sel.end, move);
     sel.col = buf_getcol(&(view->buffer), sel.end);
     view->selection = sel;
+    sync_view(view, view->selection.end);
 }
 
 void view_byline(View* view, int move) {
@@ -179,6 +184,7 @@ void view_byline(View* view, int move) {
     sel.beg = sel.end = buf_byline(&(view->buffer), sel.end, move);
     sel.beg = sel.end = buf_setcol(&(view->buffer), sel.end, sel.col);
     view->selection = sel;
+    sync_view(view, view->selection.end);
 }
 
 void view_setcursor(View* view, size_t x, size_t y) {
@@ -201,12 +207,25 @@ void view_setcursor(View* view, size_t x, size_t y) {
     //return pos;
 }
 
+void view_insert(View* view, Rune rune) {
+    if (rune == '\b') {
+        if (view->selection.end > 0)
+            buf_del(&(view->buffer), --view->selection.end);
+    } else {
+        /* ignore non-printable control characters */
+        if (!isspace(rune) && rune < 0x20)
+            return;
+        buf_ins(&(view->buffer), view->selection.end++, rune);
+    }
+    view->selection.beg = view->selection.end;
+    view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
+}
 
-
-//size_t view_getoff(View* view, size_t pos, size_t row, size_t col) {
-//    return 0;
-//}
-//
-//UGlyph* view_getglyph(View* view, size_t row, size_t col, size_t* scrwidth) {
-//    return NULL;
-//}
+void view_delete(View* view) {
+    //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);
+}
diff --git a/xedit.c b/xedit.c
index 0a3bf672bef1e750bc2da5de28b1b5251293df11..67bc7ff419e07910407107ffc19822a4c41877ff 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -49,6 +49,17 @@ static void cursor_right(void) {
     view_byrune(Focused, +1);
 }
 
+static void change_focus(void) {
+    if (Focused == &TagView) {
+        if (TagWinExpanded)
+            TagWinExpanded = false;
+        Focused = &BufView;
+    } else {
+        Focused = &TagView;
+        TagWinExpanded = true;
+    }
+}
+
 /* UI Callbacks
  *****************************************************************************/
 static void mouse_handler(MouseAct act, MouseBtn btn, int x, int y) {
@@ -69,7 +80,7 @@ static KeyBinding_T Insert[] = {
     { KEY_RIGHT,     cursor_right  },
     //{ KEY_CTRL_Q,    quit          },
     //{ KEY_CTRL_S,    write         },
-    //{ KEY_CTRL_T,    tagwin        },
+    { KEY_CTRL_T,    change_focus    },
     //{ KEY_CTRL_Z,    undo          },
     //{ KEY_CTRL_Y,    redo          },
     //{ KEY_CTRL_X,    cut           },
@@ -90,14 +101,10 @@ static void process_table(KeyBinding_T* bindings, Rune key) {
         }
         bindings++;
     }
-    /* skip control and nonprintable characters */
-    if ((!isspace(key) && key < 0x20) ||
-        (key >= 0xE000 && key <= 0xF8FF))
-        return;
-    /* fallback to just inserting the rune */
-    //buf_ins(&Buffer, SelEnd++, key);
-    //SelBeg = SelEnd;
-    //TargetCol = buf_getcol(&Buffer, SelEnd);
+    /* fallback to just inserting the rune if it doesnt fall in the private use area.
+     * the private use area is used to encode special keys */
+    if (key < 0xE000 || key > 0xF8FF)
+        view_insert(Focused, key);
 }
 
 static void key_handler(Rune key) {
@@ -183,7 +190,7 @@ static size_t draw_view(size_t off, View* view, size_t rows, size_t width) {
         draw_glyphs(2, off + ((y+1) * fheight), row->cols, row->rlen, row->len);
     }
     /* Place cursor on screen */
-    if (view == Focused)
+    if (view == Focused || view == &BufView)
         x11_draw_rect(CLR_BASE3, 2 + csrx * fwidth, off + (csry * fheight), 1, fheight);
     return (off + 4 + (rows * x11_font_height(Font)));
 }