diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 9468899..6ef7f92 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -170,7 +170,6 @@ void ReplaceText(Buffer *buffer, Range range, String16 string) { Assert(range.min >= 0 && range.min <= buffer->len); buffer->dirty = true; buffer->change_id += 1; - buffer->change_frame_id = FrameID; Int size_to_remove = range.max - range.min; Int size_to_add = string.len; diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 71a4384..e8e23f0 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -303,20 +303,20 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) { Window *last_window = GetWindow(window->title_bar_window); View *last_view = GetActiveView(last_window); Buffer *last_buffer = GetBuffer(last_view->active_buffer); + Scratch scratch; - // @todo: maybe intern the filenames? - // @leak - String filepath = ToString(Perm, buffer_string); - if (!BufferNameExists(filepath)) { - last_buffer->name = filepath; + String filepath = ToString(scratch, buffer_string); + if (filepath != last_buffer->name && !BufferNameExists(filepath)) { + // @todo: maybe intern the filenames? + // @leak + last_buffer->name = Copy(Perm, filepath); } - Scratch scratch; - String line_string = ToString(scratch, line); - String col_string = ToString(scratch, col); - Int linei = strtoll(line_string.data, NULL, 10) - 1; - Int coli = strtoll(col_string.data, NULL, 10) - 1; - Int buffer_pos = XYToPos(*last_buffer, {coli, linei}); + String line_string = ToString(scratch, line); + String col_string = ToString(scratch, col); + Int linei = strtoll(line_string.data, NULL, 10) - 1; + Int coli = strtoll(col_string.data, NULL, 10) - 1; + Int buffer_pos = XYToPos(*last_buffer, {coli, linei}); Caret &caret = last_view->carets[0]; if (GetFront(caret) != buffer_pos) { @@ -329,9 +329,7 @@ void ReplaceTitleBarData(Window *window) { view->scroll.y = 0; Buffer *buffer = GetBuffer(view->active_buffer); if (IsActive(window)) { - if (buffer->change_frame_id == FrameID) { - ApplyTitleBarChangesToWindow(window, view, buffer); - } + ApplyTitleBarChangesToWindow(window, view, buffer); return; } diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index 5446a56..ec0a1c4 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -18,7 +18,6 @@ WindowID DebugWindowID; Array WindowSwitchHistory; // @todo: probably better as a circular buffer WindowID ActiveWindow; Int CaretChangeID; -Int LastFrameIDWhenSwitchedActiveWindow; inline ViewID AllocViewID() { return {ViewIDs.id++}; } inline WindowID AllocWindowID() { return {WindowIDs.id++}; } @@ -100,17 +99,12 @@ WindowID GetLastActiveWindow() { return NullWindowID; } -bool SetActiveWindow(WindowID window) { - if (window.id != ActiveWindow.id && LastFrameIDWhenSwitchedActiveWindow != FrameID) { - LastFrameIDWhenSwitchedActiveWindow = FrameID; - ActiveWindow = window; - Window *w = GetWindow(window); - if (!w->dont_save_in_active_window_history) { - Add(&WindowSwitchHistory, window); - } - return true; +void SetActiveWindow(WindowID window) { + ActiveWindow = window; + Window *w = GetWindow(window); + if (!w->dont_save_in_active_window_history) { + Add(&WindowSwitchHistory, window); } - return false; } void SetActiveView(Window *window, ViewID view_id) { diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index d6e47b3..85da76d 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -24,7 +24,6 @@ struct Buffer { BufferID id; String name; Int change_id; - Int change_frame_id; union { U16 *data; @@ -59,6 +58,7 @@ struct Window { CircularArray view_history; WindowID title_bar_window; + Int title_bar_last_buffer_change_id; Rect2I total_rect; Rect2I scrollbar_rect; @@ -103,7 +103,12 @@ struct Scroller { Int line_count; }; -Int FrameID; +// @WARNING: be careful about using this, should only be used for debugging +// the problem with this is that we want events to be reproducible. +// We eat as many events as we can in a frame, we abstract the frame and so on. +// Dont use it +Int FrameID; + String WorkingDir; String ConfigDir; String ExeDir; diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 7b37107..6ee20c2 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,6 +1,10 @@ - bugs: - scrolling when clicking on scroller is busted - - rewrite the main loop to make sure all of code runs for frame + +- simulation: + - make the editor replayable, store events and then replay + - be careful about globals + - Windows - Mark windows as absolute or non-automatic layout and then just loop through windows diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index a114174..f7c9d4e 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -48,8 +48,8 @@ void InitWindows(View *null_view) { Buffer *buffer = CreateBuffer(sys_allocator, "*load_text_a*"); View *view = CreateView(buffer->id); // LoadTextA(buffer); - // LoadUnicode(buffer); - LoadBigTextAndBigLine(buffer, 10000000); + LoadUnicode(buffer); + // LoadBigTextAndBigLine(buffer, 10000000); window->active_view = view->id; SetActiveView(window, view->id); CreateInfobar(window);