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);
0xff2aa198, \
0xff859900 \
}
-#define DEFAULT_TAGS "Quit Save"
+#define DEFAULT_TAGS "Quit Save Cut Copy Paste | Find \n"
#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)
}
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);
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++) {
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) {
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) {
//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);
+}
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) {
{ 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 },
}
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) {
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)));
}