diff options
| author | WormHeamer | 2025-12-28 04:58:08 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-28 04:58:08 -0500 |
| commit | 5b5fe8c2ce52bd95deac0933115c7ac234aa8241 (patch) | |
| tree | 57734601918390fe68b4529b624d91e9a6ebd051 | |
| parent | 56376e5a6f5b0ab2b646711871fa975dcfd0dc97 (diff) | |
autoindent
| -rw-r--r-- | main.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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; |
