From 04e5642ce3f30f5d1cea942cd572b9743a70d865 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 4 Jan 2026 14:00:35 +0100 Subject: [PATCH] IndentKind, config is not automatically visible on start, fix automatic ReopenBuffer --- build.bat | 1 + src/backup/todo.txt | 12 ++++++------ src/text_editor/globals.cpp | 1 + src/text_editor/text_editor.cpp | 28 +++++++++++++++++----------- src/text_editor/view.cpp | 31 ++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/build.bat b/build.bat index c099011..b426364 100755 --- a/build.bat +++ b/build.bat @@ -21,6 +21,7 @@ pushd build set flags=/EHsc- /MD /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column -DDEBUG_BUILD=1 set libs=%sdllib%/SDL3-static.lib %sdllib%/SDL_uclibc.lib kernel32.lib gdi32.lib user32.lib Imm32.lib ole32.lib Shell32.lib OleAut32.lib Cfgmgr32.lib Setupapi.lib Advapi32.lib version.lib winmm.lib cl %flags% ../src/text_editor/text_editor.cpp -Fe:te.exe -I%sdl%/include -I../src/external/glad -I../src/ %libs% -link /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:MSVCRTD +copy te.exe te2.exe popd rem /fsanitize=address diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 3fb84a3..e50f149 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -1,14 +1,14 @@ ! What precise workflow do I need for me to be viable to use this? ! From a user (novice) point of view, how does it look like? -Other: -- Try out syncthing and setup the synchronized notes, maybe other things -- Write some gmail rules to forward emails from there to my proton account - - Maybe I should try out an email aggregator thing like Mozzila thunderbolt, then I will have all the data and stuff locally -- Backup all the messages on phone using a tool -- Move music and other things from phone to proton and categorize +- We need regex for: [FormatCode matching, IsCode matching, +- Variable documentation +- Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?) +- String16 string <<<@= GetString(buffer, pos_range_of_line); - here deleted space + 'string', seems like same behavior as lite but different from Sublie/VSCode +- IndentKind has issues with stuff still like cleaning whitespace etc. Use session 4 +- ListVariables instead of GenerateConfig, auto saving of variables - Option for inserting tab instead of space - Add <> <> template strings to Open (Then remove SEtWorkdirhere) - :Set Filename to name current buffer ??? :O and others like that!! diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index 8328376..17e8082 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -154,6 +154,7 @@ RegisterVariable(Int, WaitForEvents, 1); RegisterVariable(Int, DrawLineNumbers, 1); RegisterVariable(Int, DrawScrollbar, 1); RegisterVariable(Int, IndentSize, 4); +RegisterVariable(String, IndentKind, "spaces"); RegisterVariable(Int, FontSize, 15); RegisterVariable(String, WorkDir, ""); RegisterVariable(String, Font, ""); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 6d670bc..abe72df 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -477,16 +477,6 @@ void GarbageCollect() { ProfileFunction(); Allocator sys_allocator = GetSystemAllocator(); - For(Buffers) { - if (it->file_mod_time) { - int64_t new_file_mod_time = GetFileModTime(it->name); - if (it->file_mod_time != new_file_mod_time) { - it->changed_on_disk = true; - if (it->dirty == false) ReopenBuffer(it); - } - } - } - IterRemove(Views) { IterRemovePrepare(Views); @@ -665,6 +655,19 @@ void Update(Event event) { } } + For(Buffers) { + if (it->file_mod_time) { + int64_t new_file_mod_time = GetFileModTime(it->name); + if (it->file_mod_time != new_file_mod_time) { + it->changed_on_disk = true; + if (it->dirty == false) { + ReopenBuffer(it); + } + } + } + } + + GarbageCollect(); } @@ -913,10 +916,13 @@ int main(int argc, char **argv) EvalCommandsLineByLine({window, view, buffer}); } buffer->dirty = false; + if (window->active_view == view->id) { + window->active_view = NullViewID; + } } - ReportConsolef("WorkDir = %S", WorkDir); + ReportConsolef(":Set WorkDir '%S'", WorkDir); if (Testing) InitTests(); #if OS_WINDOWS CoRemove("Windows_SetupVCVarsall"); diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 5c0438d..3fcab0e 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -506,6 +506,30 @@ Array GetSelectedLinesSorted(Allocator allocator, View *view) { return result; } +char16_t GetIndentChar() { + char16_t c = u' '; + if (IndentKind == "spaces") { + c = u' '; + } else if (IndentKind == "tabs") { + c = u'\t'; + } else { + ReportErrorf("Invalid IndentKind value: %S", IndentKind); + } + return c; +} + +String16 GetIndentString(Allocator allocator) { + char16_t *result = AllocArray(allocator, char16_t, IndentSize + 1); + char16_t c = GetIndentChar(); + + for (int i = 0; i < IndentSize; i += 1) { + result[i] = c; + } + result[IndentSize] = 0; + String16 res = {result, IndentSize}; + return res; +} + void IndentSelectedLines(View *view, bool shift = false) { Scratch scratch; Buffer *buffer = GetBuffer(view->active_buffer); @@ -513,18 +537,19 @@ void IndentSelectedLines(View *view, bool shift = false) { Array edits = BeginEdit(scratch, buffer, view->carets); MergeCarets(buffer, &view->carets); + char16_t indent_char = GetIndentChar(); + String16 indent_string = GetIndentString(scratch); Array line_ranges_to_indent = GetSelectedLinesSorted(scratch, view); For(line_ranges_to_indent) { for (Int i = it.min; i < it.max; i += 1) { Range pos_range_of_line = GetLineRange(buffer, i); if (!shift) { - String16 whitespace_string = {u" ", IndentSize}; - AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string); + AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, indent_string); } else { String16 string = GetString(buffer, pos_range_of_line); Int whitespace_len = 0; - for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == ' '; i += 1) { + for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == indent_char; i += 1) { whitespace_len += 1; }