From: Michael D. Lowis Date: Fri, 30 Mar 2018 03:24:24 +0000 (-0400) Subject: refactored cursor movements X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=34147a5b4ae9354a9df7eb12bed534fcf54bfab7;p=projs%2Ftide.git refactored cursor movements --- diff --git a/inc/x11.h b/inc/x11.h index 5e23f6a..979c05b 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -107,17 +107,13 @@ enum { void x11_init(void); bool x11_keymodsset(int mask); void x11_window(char* name); - XFont x11_font_load(char* name); size_t x11_font_height(XFont fnt); size_t x11_font_width(XFont fnt); size_t x11_font_descent(XFont fnt); void x11_font_getglyph(XFont font, XGlyphSpec* spec, uint32_t rune); size_t x11_font_getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, XFont font, int x, int y); - void x11_draw_rect(int color, int x, int y, int width, int height); void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol); - bool x11_sel_get(int selid, void(*cbfn)(char*)); bool x11_sel_set(int selid, char* str); - diff --git a/lib/x11.c b/lib/x11.c index d8302b9..4d37618 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -417,8 +417,6 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol) XftColorFree(X.display, X.visual, X.colormap, &fgc); } -/******************************************************************************/ - void x11_draw_rect(int color, int x, int y, int width, int height) { XftColor clr; xftcolor(&clr, color); diff --git a/tide.c b/tide.c index 325ec79..a7b9361 100644 --- a/tide.c +++ b/tide.c @@ -124,69 +124,64 @@ static void cursor_eol(char* arg) { view_eol(win_view(FOCUSED), false); } -static void move_line_up(char* arg) { - if (!view_selsize(win_view(FOCUSED))) - select_line(arg); - cut(arg); - view_byline(win_view(FOCUSED), UP, false); - paste(arg); +/******************************************************************************/ + +static void cursor_mvlr(int dir) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + view_byword(win_view(FOCUSED), dir, extsel); + else + view_byrune(win_view(FOCUSED), dir, extsel); } -static void move_line_dn(char* arg) { - if (!view_selsize(win_view(FOCUSED))) - select_line(arg); - cut(arg); - cursor_eol(arg); - view_byrune(win_view(FOCUSED), RIGHT, false); - paste(arg); +static void cursor_mvupdn(int dir) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) { + if (!view_selsize(win_view(FOCUSED))) + select_line(0); + cut(0); + view_byline(win_view(FOCUSED), dir, false); + paste(0); + } else { + view_byline(win_view(FOCUSED), dir, extsel); + } } -static void cursor_home(char* arg) { +static void cursor_home_end( + void (*docfn)(View*, bool), + void (*linefn)(View*, bool) +) { bool extsel = x11_keymodsset(ModShift); if (x11_keymodsset(ModCtrl)) - view_bof(win_view(FOCUSED), extsel); + docfn(win_view(FOCUSED), extsel); else - view_bol(win_view(FOCUSED), extsel); + linefn(win_view(FOCUSED), extsel); +} + +/******************************************************************************/ + +static void cursor_home(char* arg) { + cursor_home_end(view_bof, view_bol); } static void cursor_end(char* arg) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_eof(win_view(FOCUSED), extsel); - else - view_eol(win_view(FOCUSED), extsel); + cursor_home_end(view_eof, view_eol); } static void cursor_up(char* arg) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - move_line_up(arg); - else - view_byline(win_view(FOCUSED), UP, extsel); + cursor_mvupdn(UP); } static void cursor_dn(char* arg) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - move_line_dn(arg); - else - view_byline(win_view(FOCUSED), DOWN, extsel); + cursor_mvupdn(DOWN); } static void cursor_left(char* arg) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_byword(win_view(FOCUSED), LEFT, extsel); - else - view_byrune(win_view(FOCUSED), LEFT, extsel); + cursor_mvlr(LEFT); } static void cursor_right(char* arg) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_byword(win_view(FOCUSED), RIGHT, extsel); - else - view_byrune(win_view(FOCUSED), RIGHT, extsel); + cursor_mvlr(RIGHT); } static void page_up(char* arg) {