From d6dd7c9eabfb5b74fc14c23d194cecb30928752d Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 12 Aug 2024 07:28:38 +0200 Subject: [PATCH] Validate buffer name uniqueness constraint, update todo --- src/text_editor/management.cpp | 15 ++++++++------- src/text_editor/title_bar.cpp | 9 ++++++++- src/text_editor/todo.txt | 22 ++++++++++++++-------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index d0b4044..7977364 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -61,6 +61,11 @@ inline Buffer *GetBuffer(String name) { return Buffers[0].o; } +inline Buffer *GetBufferStrict(String name) { + For(Buffers) if (it.o->name == name) return it.o; + return NULL; +} + inline Buffer *BufferNameExists(String name) { For(Buffers) if (it.o->name == name) return it.o; return NULL; @@ -258,24 +263,21 @@ Int ConvertUTF8ToUTF16UnixLine(String string, wchar_t *buffer, Int buffer_cap) { // - This is a worry for later time, also we want to handle weird names and so on // 3. If file exists we read it, convert to utf16, tabs to spaces etc. // +// We don't really care about opening buffers that don't have proper paths Buffer *BufferOpenFile(String path) { Allocator sys_allocator = GetSystemAllocator(); Scratch scratch; + path = GetAbsolutePath(scratch, path); Buffer *buffer = GetBuffer(path); - if (!IsNull(buffer)) { - return buffer; - } - if (IsNull(buffer) && buffer->name == path) { + if (!IsNull(buffer) || (IsNull(buffer) && buffer->name == path)) { return buffer; } if (!FileExists(path)) { - path = GetAbsolutePath(scratch, path); path = Intern(&GlobalInternTable, path); buffer = CreateBuffer(sys_allocator, path); } else if (IsDir(path)) { - path = GetAbsolutePath(scratch, path); path = Intern(&GlobalInternTable, path); buffer = CreateBuffer(sys_allocator, path, 4096 * 2); buffer->is_directory = true; @@ -284,7 +286,6 @@ Buffer *BufferOpenFile(String path) { IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.filename)); } } else { - path = GetAbsolutePath(scratch, path); path = Intern(&GlobalInternTable, path); String string = ReadFile(scratch, path); buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096); diff --git a/src/text_editor/title_bar.cpp b/src/text_editor/title_bar.cpp index 7790a69..b362bb8 100644 --- a/src/text_editor/title_bar.cpp +++ b/src/text_editor/title_bar.cpp @@ -81,7 +81,14 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) { String filepath = ToString(scratch, buffer_string); if (filepath != last_buffer->name && !BufferNameExists(filepath)) { - last_buffer->name = Intern(&GlobalInternTable, filepath); + filepath = GetAbsolutePath(scratch, filepath); + Buffer *find_buffer = GetBufferStrict(filepath); + if (find_buffer) { + ReportWarningf("couldn't set name for buffer: %.*s, there is already buffer with that name", FmtString(filepath)); + } else { + String new_name = Intern(&GlobalInternTable, filepath); + last_buffer->name = new_name; + } } Int buffer_pos = XYToPos(*last_buffer, {column, line}); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index b9359bf..1bab0f9 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,9 +1,20 @@ - garbage collect the buffers, views - store them in free list on destroy -- PageUp for some reason stops at 2 line before last line - adding items to directory should create files on save - it should ask the user (syntax: dir/ | file) +- refresh the directory - whem opening up again? +- refresh the file content, periodically check file timestamp for changes and update if neccessary +- ask user if he really wants to quit even though he has an unsaved buffer - popup window +- add plumb rules for some web stuff +- test the code editor: try writing in it, try browsing in it, create test tooling +- event serialization to lua object format +- Execute enclosure which is going to execute on every keypress, modification +- Change mouse keybindings again (left+ctrl could be load - left+ctrl could be add new cursor), exec could be middle mouse +- Store editor metadata in user accessible buffers? (read only) +- Find matches using grep, change things in that buffer then apply those changes to all items +- assert buffer name unique when createing and changing name - apply clang format - apply clang format on save +- Wait for process and get string - OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own - ctrl + f - should find Search and select content or add Search @@ -30,24 +41,20 @@ - change size of command window because it's wacky - combine glyph and selection rendering - -Windows -- better teminology then 'active' 'last active' 'current' - switch to previous view (ctrl + tab) - shift + ctrl + click should open a new window and then with alt it probably should kill it - - layout using a tree!! - - I don't think we need WindowIDs - layouting, resize windows - try to incorporate the acme square which allows you to put windows wherever and also scale the border BUG: there is a click hang when switching windows sometimes, you click after select and it doesn't switch active window +- PageUp for some reason stops at 2 line before last line +- page up and down should also scroll and leave you in exactly same scroll backlog - expose a coroutine based scripting enviorment where user can execute shell commands wait for them and perform actions in very linear manner - Test stdin writing code - Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell) - drop text into window -- page up and down should also scroll and leave you in exactly same scroll - I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection) - text_editor --record events.txt text_editor --playback events.txt - make the editor replayable, store events and then replay, be careful about globals @@ -57,4 +64,3 @@ backlog - font cache and on demand unicode loads - Set scroll centered, what was the use case for this? - color parens, braces -- auto register commands, but we need to figure out how to properly structure lua stuff \ No newline at end of file