From: Michael D. Lowis Date: Thu, 27 Sep 2018 13:37:17 +0000 (-0400) Subject: revised font loading so bad font arguments don't cause the editor to exit X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c2626987cb5e722936ea63f4e0376549a9d2af73;p=projs%2Ftide.git revised font loading so bad font arguments don't cause the editor to exit --- diff --git a/TODO.md b/TODO.md index d3bdb41..3e3c28b 100644 --- a/TODO.md +++ b/TODO.md @@ -7,6 +7,7 @@ * gap buffer does not handle UTF-8 currently * mouse selection handling when mouse moves outside region * Line - Get the current line number(s) containing the selection +* refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend) ## BACKLOG diff --git a/lib/view.c b/lib/view.c index 9fcb9c8..50b0d50 100644 --- a/lib/view.c +++ b/lib/view.c @@ -265,12 +265,12 @@ void view_insert(View* view, Rune rune) { size_t n = (TabWidth - ((off - buf_bol(BUF, off)) % TabWidth)); for (; n > 0; n--) buf_putc(BUF, ' '); } else if (CopyIndent && rune == '\n') { - size_t off = buf_selbeg(BUF); - size_t beg = buf_bol(BUF, off-1), end = beg; - for (; end < buf_end(BUF) && (' ' == buf_getrat(BUF, end) || '\t' == buf_getrat(BUF, end)); end++); + size_t off = buf_selbeg(BUF); + size_t beg = buf_bol(BUF, off-1), end = beg; + for (; end < buf_end(BUF) && (' ' == buf_getrat(BUF, end) || '\t' == buf_getrat(BUF, end)); end++); buf_putc(BUF, '\n'); for (; beg < end; beg++) - buf_putc(BUF, buf_getrat(BUF, beg)); + buf_putc(BUF, buf_getrat(BUF, beg)); } else { buf_putc(BUF, rune); } diff --git a/lib/x11.c b/lib/x11.c index 620f3bb..fac3632 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -78,7 +78,11 @@ static void font_load(char* name) { /* load the base font */ FcResult result; FcPattern* match = XftFontMatch(X.display, X.screen, pattern, &result); - if (!match || !(X.font = XftFontOpenPattern(X.display, match))) + if (match) { + XftFont* font = XftFontOpenPattern(X.display, match); + X.font = (font ? font : X.font); // Update if we found a new font + } + if (!X.font) die("could not load base font\n"); FcPatternDestroy(pattern); FcPatternDestroy(match);