]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented logic to expand tabs
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 13 Sep 2018 15:49:46 +0000 (11:49 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 13 Sep 2018 15:49:46 +0000 (11:49 -0400)
TODO.md
inc/edit.h
lib/buf.c
lib/view.c

diff --git a/TODO.md b/TODO.md
index a2c16ba81740915736733b527af07e0e9077ab3c..5013dbf3660e8f8509cec39be55e84c98bda735d 100644 (file)
--- 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:
 
index 60de10fd5f40c3569ffc6366a694a23a9d711798..08fcd09d65b508087e998fd74c0b7aa70550f610 100644 (file)
@@ -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);
index 4ef2da98a6f73eaaa6f1ee3f731b02bd456f776b..cfe47b567c9f1a7b8b9e5bd367ccc333e759c89f 100644 (file)
--- 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;
index 08db6f6cb69a74d8d9f0b1225783500bb94d612b..8dce23b4778a06d531f24d0c0e31983e26565e81 100644 (file)
@@ -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);
 }