From 2df74ed6a388cd2999fb6c4ccbf58ab044b95c72 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 14 Nov 2016 20:01:05 -0500 Subject: [PATCH] Added logic to show and hide the tag buffer while keeping the selection visible in the edit buffer --- config.mk | 2 +- inc/edit.h | 3 ++- libedit/view.c | 37 ++++++++++++++++++++++++++++--------- xedit.c | 27 +++++++++++++++++---------- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/config.mk b/config.mk index fc63cfe..b9996f6 100644 --- a/config.mk +++ b/config.mk @@ -2,7 +2,7 @@ # Compiler Setup CC = c99 -CFLAGS = -Os $(INCS) +CFLAGS = -O0 $(INCS) # Linker Setup LD = $(CC) diff --git a/inc/edit.h b/inc/edit.h index 2f42f6c..d684a3f 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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" diff --git a/libedit/view.c b/libedit/view.c index 9ddd0b7..b4a1d8e 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -1,6 +1,7 @@ #include #include #include +#include #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 0a3bf67..67bc7ff 100644 --- 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))); } -- 2.52.0