From: Michael D. Lowis Date: Tue, 4 Jul 2017 02:34:52 +0000 (-0400) Subject: tweaked line selection behavior to highlight entire line instead of just the text X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1084e24ba52ed444c5bee5418156c6130010719a;p=projs%2Ftide.git tweaked line selection behavior to highlight entire line instead of just the text --- diff --git a/TODO.md b/TODO.md index 0588268..da354ce 100644 --- a/TODO.md +++ b/TODO.md @@ -88,17 +88,10 @@ Region GROUP start=REGEX skip=REGEX end=REGEX https://www.slant.co/topics/358/~best-color-themes-for-text-editors * Wily -* Gruvbox * badwolf * jelly beans -* monokai/molokai -* tomorrow -* spacegray -* base16 -* dracula * one dark * zenburn -* ayu * railscast * material * spacemacs @@ -106,13 +99,9 @@ https://www.slant.co/topics/358/~best-color-themes-for-text-editors * soda light * predawn * lucario -* vim desert -* two firewatch * obsidian * leuven * afterglow -* apathy -* vim guru * nord * plastic code wrap * wombat diff --git a/inc/x11.h b/inc/x11.h index bb3c746..a78e000 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -142,7 +142,7 @@ size_t x11_font_getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, XFon void x11_draw_rect(int color, int x, int y, int width, int height); void x11_draw_utf8(XFont font, int fg, int bg, int x, int y, char* str); -void x11_draw_glyphs(int fg, int bg, XGlyphSpec* glyphs, size_t nglyphs); +void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol); void x11_draw_utf8(XFont font, int fg, int bg, int x, int y, char* str); bool x11_sel_get(int selid, void(*cbfn)(char*)); diff --git a/lib/view.c b/lib/view.c index d7104a2..36a7b1b 100644 --- a/lib/view.c +++ b/lib/view.c @@ -548,7 +548,9 @@ static size_t setcell(View* view, size_t row, size_t col, uint32_t attr, Rune r) int ncols = runewidth(col, r); /* write the rune to the screen buf */ scrrow->cols[col].attr = attr; - if (r == '\t' || r == '\n' || r == RUNE_CRLF) + if (r == RUNE_CRLF) + scrrow->cols[col].rune = '\n'; + else if (r == '\t') scrrow->cols[col].rune = ' '; else scrrow->cols[col].rune = r; diff --git a/lib/win.c b/lib/win.c index f08d310..3f68dc6 100644 --- a/lib/win.c +++ b/lib/win.c @@ -416,10 +416,13 @@ static void draw_line_num(bool current, size_t x, size_t y, size_t gcols, size_t static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols) { XGlyphSpec specs[rlen]; size_t i = 0; + bool eol = false; while (rlen && i < ncols) { int numspecs = 0; uint32_t attr = glyphs[i].attr; while (i < ncols && glyphs[i].attr == attr) { + if (glyphs[i].rune == '\n') + glyphs[i].rune = ' ', eol = true; x11_font_getglyph(Font, &(specs[numspecs]), glyphs[i].rune); specs[numspecs].x = x; specs[numspecs].y = y - x11_font_descent(Font); @@ -433,8 +436,8 @@ static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t /* Draw the glyphs with the proper colors */ uint8_t bg = attr >> 8; uint8_t fg = attr & 0xFF; - x11_draw_glyphs(fg, bg, specs, numspecs); - rlen -= numspecs; + x11_draw_glyphs(fg, bg, specs, numspecs, eol); + eol = false, rlen -= numspecs; } } diff --git a/lib/x11.c b/lib/x11.c index 17530cd..5e9e2cd 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -436,7 +436,7 @@ void x11_font_getglyph(XFont fnt, XGlyphSpec* spec, uint32_t rune) { /* Otherwise check the cache */ for (int f = 0; f < font->ncached; f++) { glyphidx = XftCharIndex(X.display, font->cache[f].font, rune); - /* Fond a suitable font or found a default font */ + /* Found a suitable font or found a default font */ if (glyphidx || (!glyphidx && font->cache[f].unicodep == rune)) { spec->font = font->cache[f].font; spec->glyph = glyphidx; @@ -488,10 +488,11 @@ size_t x11_font_getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, XFon return numspecs; } -void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs) { +void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol) { if (!nspecs) return; XftFont* font = specs[0].font; XftColor fgc, bgc; + if (bg > 0) { XGlyphInfo extent; XftTextExtentsUtf8(X.display, font, (const FcChar8*)"0", 1, &extent); @@ -499,6 +500,7 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs) { int h = (font->height - font->descent) + config_get_int(LineSpacing); xftcolor(&bgc, bg); size_t width = specs[nspecs-1].x - specs[0].x + w; + if (eol) width = X.width - specs[0].x; x11_draw_rect(bg, specs[0].x, specs[0].y - h, width, font->height + config_get_int(LineSpacing)); XftColorFree(X.display, X.visual, X.colormap, &bgc); } @@ -519,7 +521,7 @@ void x11_draw_utf8(XFont fnt, int fg, int bg, int x, int y, char* str) { nspecs++; str++; } - x11_draw_glyphs(fg, bg, (XGlyphSpec*)specs, nspecs); + x11_draw_glyphs(fg, bg, (XGlyphSpec*)specs, nspecs, false); } /* Selection Handling diff --git a/pick.c b/pick.c index ee5e183..801b9a3 100644 --- a/pick.c +++ b/pick.c @@ -146,7 +146,7 @@ void onupdate(void) { view_insert(view, false, *str); view_insert(view, false, '\n'); if (ChoiceIdx == i+off) { - selection.beg = view->selection.end-1; + selection.beg = view->selection.end; selection.end = beg; } }