diff --git a/src/backup/todo.txt b/src/backup/todo.txt index be79d42..8aaff3c 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -3,12 +3,16 @@ Use session 1: - OpenCommand in command window freezes the app -- Shift + backspace should delete normally - SDL popups are not working on linux ... + - CloseAll idea: should create a buffer interface with list of buffers, user would be able to select which buffers to save and which not, then button UICloseAll - Creating files more efficiently - Dialog popup on save? Or ctrl-shift-s? - Maybe rename in bar and do :Rename +New UI Session +- Cleanup String16/String with Open and EvalCommands after lua refactor +- Rename GotoBackward and others to Jump + - 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?) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index ba14344..0007e71 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -829,6 +829,52 @@ void Command_CloseAll() { } } RegisterCommand(Command_CloseAll, ""); +void Command_ForceClose() { + BSet active = GetBSet(ActiveWindowID); + Close(active.buffer->id); + Close(active.view->id); +} + +// @todo: make these uneditable? +// @todo: maybe turn this into a coroutine??? +String BufferIDea = R"==( +Do you want to save buffer? [C:/Programming/text_editor/build.sh] + + :Yes :No +)=="; +void Command_TestUIIdea() { + BSet main = GetBSet(LastActiveLayoutWindowID); + JumpGarbageBuffer(&main, "ui"); + NextActiveWindowID = main.window->id; + + Add(&main.view->hooks, {"Yes", "enter", [](){ + BSet active = GetBSet(ActiveWindowID); + Caret a = FindNext(active.buffer, u"[", MakeCaret(0)); + Caret b = FindNext(active.buffer, u"]", MakeCaret(0)); + if (GetSize(a) == 0 || GetSize(b) == 0) { + ReportWarningf("Failed to save, '[' or ']' not found"); + return; + } + + Scratch scratch; + String16 string16 = GetString(active.buffer, {a.range.max, b.range.min}); + String string = ToString(scratch, string16); + Buffer *buffer = GetBuffer(string, NULL); + if (buffer) { + SaveBuffer(buffer); + } else { + ReportWarningf("Failed to save, buffer not found: %S", string); + } + + Close(active.buffer->id); + Close(active.view->id); + }, ParseKey(Perm, "enter", "Command_TestUIIdea_Yes")}); // @todo: fix memory leak + Add(&main.view->hooks, {"No", "escape", Command_ForceClose, ParseKeyCached("escape")}); + RawAppend(main.buffer, BufferIDea); + main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0)); + main.view->carets[0].range.min = main.view->carets[0].range.max; +} RegisterCommand(Command_TestUIIdea, ""); + void Command_GotoBackward() { BSet main = GetBSet(LastActiveLayoutWindowID); main.window->skip_checkpoint = true; @@ -1084,7 +1130,7 @@ void Command_DeleteBoundary() { void Command_DeleteForward() { BSet active = GetBSet(ActiveWindowID); Delete(active.view, DIR_RIGHT); -} RegisterCommand(Command_DeleteForward, "delete"); +} RegisterCommand(Command_DeleteForward, "shift-delete | delete"); void Command_DeleteForwardBoundary() { BSet active = GetBSet(ActiveWindowID); diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index ee464d3..e7f020b 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -79,7 +79,7 @@ String Intern(InternTable *table, String string) { // optimize worst offenders (like event text) InternTable GlobalInternTable; -Function *LastExecutedCommand; +Function *LastExecutedManualCommand; Array CommandFunctions; Array TestFunctions; Array Variables; diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 6d27fc7..bacd6f7 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -386,11 +386,24 @@ void OnCommand(Event event) { BSet main = GetBSet(LastActiveLayoutWindowID); BSet active = GetBSet(ActiveWindowID); - For (CommandFunctions) { + bool executed = false; + For (active.view->hooks) { if (it.trigger && MatchEvent(it.trigger, &event)) { ProfileScopeEx(it.name); it.function(); - LastExecutedCommand = it.function; + LastExecutedManualCommand = it.function; + executed = true; + break; + } + } + + if (executed == false) { + For (CommandFunctions) { + if (it.trigger && MatchEvent(it.trigger, &event)) { + ProfileScopeEx(it.name); + it.function(); + LastExecutedManualCommand = it.function; + } } } @@ -476,8 +489,7 @@ void GarbageCollect() { RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer->name); remove_item = true; - Dealloc(&it->carets); - Dealloc(sys_allocator, it); + Dealloc(it); } IterRemove(Buffers) { diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index cf4eb16..d7e9394 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -8,11 +8,18 @@ API View *CreateView(BufferID active_buffer) { view->id = AllocViewID(view); view->active_buffer = active_buffer; view->carets.allocator = al; + view->hooks.allocator = al; Add(&view->carets, {0, 0}); Add(&Views, view); return view; } +void Dealloc(View *view) { + Dealloc(&view->carets); + Dealloc(&view->hooks); + Dealloc(view->carets.allocator, view); +} + API View *FindView(ViewID view_id, View *default_view) { For(Views) { if (it->id == view_id) { diff --git a/src/text_editor/view.h b/src/text_editor/view.h index c0a534b..878e4c9 100644 --- a/src/text_editor/view.h +++ b/src/text_editor/view.h @@ -1,6 +1,10 @@ struct View; struct ViewID { Int id; View *o; }; +typedef void Function(); +struct FunctionData { String name; Function *function; }; +struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; }; + struct View { ViewID id; BufferID active_buffer; @@ -11,6 +15,7 @@ struct View { Caret main_caret_on_begin_frame; bool update_scroll; + Array hooks; String16 prev_search_line; struct { unsigned close : 1; diff --git a/src/text_editor/window.h b/src/text_editor/window.h index 56aab63..ee4748e 100644 --- a/src/text_editor/window.h +++ b/src/text_editor/window.h @@ -36,7 +36,6 @@ struct Window { uint32_t lose_focus_on_escape : 1; uint32_t lose_visibility_on_escape : 1; uint32_t jump_history : 1; - uint32_t eval_command : 1; uint32_t skip_checkpoint : 1; }; }; diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index f4a2425..e658e2a 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -110,7 +110,7 @@ void CommandWindowUpdate() { } void Command_ShowCommands() { - if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) { + if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowCommands) { NextActiveWindowID = LastActiveLayoutWindowID; return; } @@ -118,18 +118,20 @@ void Command_ShowCommands() { BSet command_bar = GetBSet(CommandWindowID); command_bar.window->visible = true; - command_bar.window->eval_command = true; NextActiveWindowID = command_bar.window->id; ResetBuffer(command_bar.buffer); - For(CommandFunctions) { - RawAppendf(command_bar.buffer, "\n%S", it.name); + For (CommandFunctions) { + if (it.name == "OpenCommand") { + continue; + } + RawAppendf(command_bar.buffer, "\n:%S", it.name); } command_bar.view->update_scroll = true; SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); } RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); void Command_ShowDebugBufferList() { - if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) { + if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowDebugBufferList) { NextActiveWindowID = LastActiveLayoutWindowID; return; } @@ -137,7 +139,6 @@ void Command_ShowDebugBufferList() { BSet command_bar = GetBSet(CommandWindowID); command_bar.window->visible = true; - command_bar.window->eval_command = false; NextActiveWindowID = command_bar.window->id; ResetBuffer(command_bar.buffer); For (Buffers) { @@ -148,7 +149,7 @@ void Command_ShowDebugBufferList() { } RegisterCommand(Command_ShowDebugBufferList, ""); void Command_ShowBufferList() { - if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) { + if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowBufferList) { NextActiveWindowID = LastActiveLayoutWindowID; return; } @@ -156,7 +157,6 @@ void Command_ShowBufferList() { BSet command_bar = GetBSet(CommandWindowID); command_bar.window->visible = true; - command_bar.window->eval_command = false; NextActiveWindowID = command_bar.window->id; ResetBuffer(command_bar.buffer); For (Buffers) { @@ -178,20 +178,10 @@ void OpenCommand(BSet active) { if (line == 0) { line = ClampTop(1ll, active.buffer->line_starts.len - 1ll); } - string = GetLineStringWithoutNL(active.buffer, line); - Int idx = 0; - if (Seek(string, u"||", &idx)) { - string = Skip(string, idx + 3); - } - } - if (active.window->eval_command) { - BSet main = GetBSet(LastActiveLayoutWindowID); - NextActiveWindowID = main.window->id; - EvalCommand(string); - } else { - Open(string); } + + Open(string); } void Command_OpenCommand() { @@ -199,5 +189,7 @@ void Command_OpenCommand() { return; } BSet active = GetBSet(ActiveWindowID); + BSet main = GetBSet(LastActiveLayoutWindowID); + NextActiveWindowID = main.window->id; OpenCommand(active); -} RegisterCommand(Command_OpenCommand, "ctrl-q | enter"); \ No newline at end of file +} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");