From a96cead179e939a81c49210fd4bbd7efcea1c6d7 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 6 Jan 2026 14:15:20 +0100 Subject: [PATCH] Fix indenting --- src/text_editor/view.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 04fab35..df5250e 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -150,26 +150,24 @@ String16 GetIndentString(Allocator allocator, Int indent_size) { char16_t *result = AllocArray(allocator, char16_t, indent_size + 1); char16_t c = GetIndentChar(); - for (int i = 0; i < IndentSize; i += 1) { + for (int i = 0; i < indent_size; i += 1) { result[i] = c; } - result[IndentSize] = 0; + result[indent_size] = 0; String16 res = {result, indent_size}; return res; } -Int FindScopeIndent(Buffer *buffer, Int pos) { - for (Int i = pos - 1; i >= 0; i -= 1) { - if (buffer->str[i] == '{' || buffer->str[i] == '[' || buffer->str[i] == '(') { - Int line = PosToLine(buffer, pos); - return GetLineIndent(buffer, line) + IndentSize; - } - if (buffer->str[i] == '}' || buffer->str[i] == ']' || buffer->str[i] == ')') { - Int line = PosToLine(buffer, pos); - return GetLineIndent(buffer, line); - } +String GetIndentString8(Allocator allocator, Int indent_size) { + char *result = AllocArray(allocator, char, indent_size + 1); + char c = (char)GetIndentChar(); + + for (int i = 0; i < indent_size; i += 1) { + result[i] = c; } - return 0; + result[indent_size] = 0; + String res = {result, indent_size}; + return res; } void IndentedNewLine(View *view) { @@ -180,7 +178,8 @@ void IndentedNewLine(View *view) { For(view->carets) { Int front = GetFront(it); Int indent = GetLineIndent(buffer, PosToLine(buffer, front)); - String string = Format(scratch, "\n%S", GetIndentString(scratch, indent)); + String indent_string = GetIndentString8(scratch, indent); + String string = Format(scratch, "\n%S", indent_string); String16 string16 = ToString16(scratch, string); AddEdit(&edits, it.range, string16); } @@ -604,7 +603,9 @@ Array ReplaceEx(Allocator scratch, View *view, String16 string) { Buffer *buffer = GetBuffer(view->active_buffer); Array edits = BeginEdit(scratch, buffer, view->carets); MergeCarets(buffer, &view->carets); - For(view->carets) AddEdit(&edits, it.range, string); + For(view->carets) { + AddEdit(&edits, it.range, string); + } EndEdit(buffer, &edits, &view->carets, KILL_SELECTION); return edits; }