From c8aaf7470986993a27bb4774783528aca8a45af5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 13 Sep 2018 11:49:46 -0400 Subject: [PATCH] implemented logic to expand tabs --- TODO.md | 9 ++++----- inc/edit.h | 1 + lib/buf.c | 5 +++++ lib/view.c | 8 +++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index a2c16ba..5013dbf 100644 --- a/TODO.md +++ b/TODO.md @@ -2,14 +2,13 @@ BUGS: -* no copy indent -* characters missing from riscmd: |+- * no analysis of line-endings or tabs in document -* no trimming of trailing whitespace +* no copy indent +* add arguments to keybindings +* mouse selection handling when mouse moves outside region * no magic right click -* Ctrl+Up,Dn not bound or not working * gap buffer does not handle UTF-8 currently -* mouse selection handling when mouse moves outside region +* no trimming of trailing whitespace Up Next: diff --git a/inc/edit.h b/inc/edit.h index 60de10f..08fcd09 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -73,6 +73,7 @@ void buf_setln(Buf* buf, size_t line); void buf_getcol(Buf* buf); void buf_setcol(Buf* buf); +size_t buf_selbeg(Buf* buf); size_t buf_selsz(Buf* buf); void buf_selclr(Buf* buf, int dir); bool buf_insel(Buf* buf, size_t off); diff --git a/lib/buf.c b/lib/buf.c index 4ef2da9..cfe47b5 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -568,6 +568,11 @@ void buf_setcol(Buf* buf) { buf->selection = sel; } +size_t buf_selbeg(Buf* buf) { + Sel sel = buf_getsel(buf); + return (sel.beg < sel.end ? sel.beg : sel.end); +} + size_t buf_selsz(Buf* buf) { Sel sel = buf_getsel(buf); return sel.end - sel.beg; diff --git a/lib/view.c b/lib/view.c index 08db6f6..8dce23b 100644 --- a/lib/view.c +++ b/lib/view.c @@ -259,7 +259,13 @@ void view_insert(View* view, bool indent, Rune rune) { /* ignore non-printable control characters */ if (!isspace(rune) && (rune >= 0 && rune < 0x20)) return; - buf_putc(BUF, rune); + if (ExpandTabs && rune == '\t') { + size_t off = buf_selbeg(BUF); + size_t n = (TabWidth - ((off - buf_bol(BUF, off)) % TabWidth)); + for (; n > 0; n--) buf_putc(BUF, ' '); + } else { + buf_putc(BUF, rune); + } move_to(view, false, CSRPOS); } -- 2.49.0