From 5b5fe8c2ce52bd95deac0933115c7ac234aa8241 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sun, 28 Dec 2025 04:58:08 -0500 Subject: autoindent --- main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 0866310..31b9354 100644 --- a/main.c +++ b/main.c @@ -172,7 +172,7 @@ void draw(void *ctx) { TxtLoc start, end; find_view_window(&txt, cur, &start, &end); - vui_aprintf(-1, 0, ODD_ATTR, "%u pieces", txt.ptbl.n); + vui_aprintf(-1, 0, ODD_ATTR, "%u piece(s)", txt.ptbl.n); for (u32 i = 0; i < txt.ptbl.n; i++) { TxtPiece *p = &txt.ptbl.v[i]; VuiAttr a = i&1 ? ODD_ATTR : EVEN_ATTR; @@ -273,9 +273,17 @@ int main(int argc, const char **argv) { txt_save(&txt, path); //txt_load(&txt, "test.txt"); break; - case '\r': + case '\r': { + u32 tabs = 0; + TxtLoc start = start_of_line(&txt, txt_at(&txt, cur)); + for (TxtLoc l = start; txt_byte(&txt, l) == '\t'; l = txt_next(&txt, l)) + tabs++; + while (txt_byte(&txt, txt_at(&txt, cur - 1)) == '\t') { + cur = txt_delete(&txt, cur, 1); + } cur = txt_insert_c(&txt, cur, '\n'); - break; + while (tabs--) cur = txt_insert_c(&txt, cur, '\t'); + } break; default: if ((c == '\t' || c >= ' ') && c <= KEY_UTF8_MAX) cur = txt_insert_c(&txt, cur, c); break; -- cgit v1.2.3