IndentKind, config is not automatically visible on start, fix automatic ReopenBuffer

This commit is contained in:
Krzosa Karol
2026-01-04 14:00:35 +01:00
parent f059c33940
commit 04e5642ce3
5 changed files with 53 additions and 20 deletions

View File

@@ -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

View File

@@ -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 <<File>> <<WorkDir>> template strings to Open (Then remove SEtWorkdirhere)
- :Set Filename to name current buffer ??? :O and others like that!!

View File

@@ -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, "");

View File

@@ -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");

View File

@@ -506,6 +506,30 @@ Array<Range> 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<Edit> edits = BeginEdit(scratch, buffer, view->carets);
MergeCarets(buffer, &view->carets);
char16_t indent_char = GetIndentChar();
String16 indent_string = GetIndentString(scratch);
Array<Range> 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;
}