From 1011c634948879824b9c8d0b89c2f30a0c611131 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 27 Dec 2025 21:37:41 +0100 Subject: [PATCH] Open dir, small fixes --- src/backup/todo.txt | 10 ++++++++++ src/basic/basic_os.cpp | 5 +---- src/text_editor/buffer.cpp | 2 +- src/text_editor/commands.cpp | 13 ++++++------- src/text_editor/text_editor.cpp | 7 ++++++- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 2d2b9d5..be79d42 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -1,6 +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? +Use session 1: +- OpenCommand in command window freezes the app +- Shift + backspace should delete normally +- SDL popups are not working on linux ... +- Creating files more efficiently + - Dialog popup on save? Or ctrl-shift-s? + - Maybe rename in bar and do :Rename + - Open with seek string (open at pattern) filename:32 filename:/^Window$/ - build console window - Show what process/coroutines are running and allow to kill (active process buffer?) @@ -11,6 +19,8 @@ - Why constraint that name of buffer needs to be unique? For Open() and default behavior but is this required? - Try to add Tracking Allocator and rewrite the app, free all memory at the end of the app and check all is well +- Maybe fix OS layer returning with "/" at the end for directories + - Fix open code pattern Commands TODO: - Console: OK concept but constrain diff --git a/src/basic/basic_os.cpp b/src/basic/basic_os.cpp index 1a4d9d8..a9e5da9 100644 --- a/src/basic/basic_os.cpp +++ b/src/basic/basic_os.cpp @@ -293,11 +293,8 @@ API Process SpawnProcess(String command_line, String working_dir, String write_s const int PIPE_WRITE = 1; bool error = false; - char *buffer = AllocArray(scratch, char, 4096); + working_dir = Copy(scratch, working_dir); chdir(working_dir.data); - getcwd(buffer, 4096); - defer { chdir(buffer); }; - Process process = {}; UnixProcess *plat = (UnixProcess *)&process.platform; diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index ab5bb59..2963fee 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -1435,7 +1435,7 @@ String GetUniqueBufferName(String working_dir, String prepend_name, String exten void InitBuffers() { Allocator sys_allocator = GetSystemAllocator(); Scratch scratch; - Buffer *null_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(GetWorkingDir(scratch), "console")); + Buffer *null_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "console")); null_buffer->special = true; View *null_view = CreateView(null_buffer->id); null_view->special = true; diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 80e7422..6516b62 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -454,7 +454,7 @@ void Command_Build() { #if OS_WINDOWS ExecBuild("build.bat"); #else - ExecBuild("./build.sh"); + ExecBuild("sh build.sh"); #endif } RegisterCommand(Command_Build, "f1"); @@ -701,10 +701,10 @@ void Command_ToggleFullscreen() { void Command_SetWorkDir() { BSet main = GetBSet(LastActiveLayoutWindowID); - WorkDir = ChopLastSlash(main.buffer->name); + WorkDir = GetDir(main.buffer); } RegisterCommand(Command_SetWorkDir, ""); -String CodeSkipEndings[] = {".git" }; +String CodeSkipPatterns[] = {".git/"}; String Coro_OpenCodeDir; void Coro_OpenCode(mco_coro *co) { @@ -714,16 +714,15 @@ void Coro_OpenCode(mco_coro *co) { int i = 0; for (int diri = 0; diri < dirs.len; diri += 1) { for (FileIter it = IterateFiles(arena, dirs[diri]); IsValid(it); Advance(&it)) { - bool match = false; - for (int endings_i = 0; endings_i < Lengthof(CodeSkipEndings); endings_i += 1) { - String ending = CodeSkipEndings[endings_i]; + for (int endings_i = 0; endings_i < Lengthof(CodeSkipPatterns); endings_i += 1) { + String ending = CodeSkipPatterns[endings_i]; if (EndsWith(it.absolute_path, ending)) { match = true; break; } } - if (match) break; + if (match) continue; if (it.is_directory) { diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 4a7bf19..c0908de 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -796,8 +796,13 @@ int main(int argc, char **argv) if (it == "--testing") { Testing = true; + } else if (IsDir(it)) { + WorkDir = GetAbsolutePath(Perm, it); + OpenCode(WorkDir); } else { - if (!FileExists(it)) continue; + if (!FileExists(it)) { + continue; + } Window *window = GetWindow({0}); WindowOpenBufferView(window, it); }