From 872c46c43d8cabb521ebdc856d342944c2fd8d2d Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 12 May 2025 08:53:42 +0200 Subject: [PATCH] Search bar anchor --- src/basic/filesystem.h | 11 ++++++++++- src/basic/win32.cpp | 7 ------- src/text_editor/commands.cpp | 1 - src/text_editor/commands_bindings.cpp | 10 ++++++++++ src/text_editor/text_editor.h | 12 ++---------- src/text_editor/todo.txt | 4 +--- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/basic/filesystem.h b/src/basic/filesystem.h index 4cd5687..3fb69d0 100644 --- a/src/basic/filesystem.h +++ b/src/basic/filesystem.h @@ -49,4 +49,13 @@ String PollStdout(Allocator allocator, Process *process); void WriteStdin(Process *process, String string); void CloseStdin(Process *process); -double get_time_in_micros(void); \ No newline at end of file +double get_time_in_micros(void); + +enum MakeDirResult { + MakeDirResult_Success, + MakeDirResult_Exists, + MakeDirResult_NotFound, + MakeDirResult_ErrorOther, +}; + +MakeDirResult MakeDir(String path); \ No newline at end of file diff --git a/src/basic/win32.cpp b/src/basic/win32.cpp index 17a0813..48db667 100644 --- a/src/basic/win32.cpp +++ b/src/basic/win32.cpp @@ -276,13 +276,6 @@ int64_t GetFileModTime(String file) { } } -enum MakeDirResult { - MakeDirResult_Success, - MakeDirResult_Exists, - MakeDirResult_NotFound, - MakeDirResult_ErrorOther, -}; - MakeDirResult MakeDir(String path) { Scratch scratch; MakeDirResult result = MakeDirResult_Success; diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index f5d8b28..a52cc9f 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -248,7 +248,6 @@ void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = f BSet set = GetBSet(window); CheckpointBeforeGoto(window); - Rect2I visible_cells_rect = GetVisibleCells(window); Int y = GetSize(visible_cells_rect).y - 2; if (direction == DIR_UP) y = -y; diff --git a/src/text_editor/commands_bindings.cpp b/src/text_editor/commands_bindings.cpp index aed39ec..6c4c7db 100644 --- a/src/text_editor/commands_bindings.cpp +++ b/src/text_editor/commands_bindings.cpp @@ -446,10 +446,12 @@ void OnCommand(Event event) { } else if (AltShiftPress(SDLK_DOWN)) { Command_CreateCursorVertical(active.view, DIR_DOWN); } else if (CtrlShiftPress(SDLK_DOWN)) { + CheckpointBeforeGoto(active.window); Command_Move(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED); } else if (AltPress(SDLK_DOWN)) { Command_MoveLine(active.view, DIR_DOWN); } else if (CtrlPress(SDLK_DOWN)) { + CheckpointBeforeGoto(active.window); Command_Move(active.view, DIR_DOWN, CTRL_PRESSED); } else if (ShiftPress(SDLK_DOWN)) { Command_Move(active.view, DIR_DOWN, false, SHIFT_PRESSED); @@ -462,10 +464,12 @@ void OnCommand(Event event) { } else if (AltShiftPress(SDLK_UP)) { Command_CreateCursorVertical(active.view, DIR_UP); } else if (CtrlShiftPress(SDLK_UP)) { + CheckpointBeforeGoto(active.window); Command_Move(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESSED); } else if (AltPress(SDLK_UP)) { Command_MoveLine(active.view, DIR_UP); } else if (CtrlPress(SDLK_UP)) { + CheckpointBeforeGoto(active.window); Command_Move(active.view, DIR_UP, CTRL_PRESSED); } else if (ShiftPress(SDLK_UP)) { Command_Move(active.view, DIR_UP, false, SHIFT_PRESSED); @@ -593,11 +597,15 @@ void OnCommand(Event event) { Scratch scratch; String16 search_string = GetSearchString(main.window); Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]); + BSet search = GetBSet(main.window->search_bar_window); + search.window->search_bar_anchor = caret; Command_SelectRangeOneCursor(main.view, caret); } else if (Press(SDLK_F3)) { Scratch scratch; String16 search_string = GetSearchString(main.window); Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]); + BSet search = GetBSet(main.window->search_bar_window); + search.window->search_bar_anchor = caret; Command_SelectRangeOneCursor(main.view, caret); } @@ -619,6 +627,7 @@ void OnCommand(Event event) { } Command_SelectEntireBuffer(search.view); search.window->visible = 1; + search.window->search_bar_anchor = main.view->carets[0]; ActiveWindow = search.window->id; } } @@ -719,6 +728,7 @@ void OnCommand(Event event) { } if (active.window->is_search_bar && buffer_change_id != active.buffer->change_id) { + main.view->carets[0] = active.window->search_bar_anchor; Command_Find(main.view, GetSearchString(main.window), true); } diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 2b996d0..eb8c579 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -1,6 +1,6 @@ struct Window; struct View; struct WindowSplit; struct ViewID { Int id; View *o; }; -struct WindowID { Int id; Window *o; }; // @todo: change name of object to something scary +struct WindowID { Int id; Window *o; }; struct View { @@ -47,6 +47,7 @@ struct Window { ViewID active_goto_list; Int goto_list_pos; + Caret search_bar_anchor; double mouse_scroller_offset; int z; @@ -93,15 +94,6 @@ struct BSet { Buffer *buffer; }; -enum MakeDirResult { - MakeDirResult_Success, - MakeDirResult_Exists, - MakeDirResult_NotFound, - MakeDirResult_ErrorOther, -}; - -MakeDirResult MakeDir(String path); - // @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. diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index dc21117..56e9d36 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -8,6 +8,7 @@ - Lua OnCommand should be able to comunicate that we don't want C handling and do only the Lua handling - Easily programmable F1-F12 commands - Lua namespaces for different kinds of commands (by ids, using main_set, using active_set)? +- List all files in project, exclude by lua pattern - Set window layout using project file - Split command @@ -17,19 +18,16 @@ - Set active window using id - Fix jump scroll, the query ends up the last line on screen, kind of wacky - Fix Ctrl+1 Ctrl+2 (choosing window) -- Fix search, should have an anchor - Use project file as working dir instead of scratch buffer path, separate project dir and project file - Remedybg integration - GetLine() - in lua start debugging, jump to line, start debugger on file -- Enclose scope - save all relevant buffers and build - maybe most of the bindings should be in lua, but actual code in C - maybe less code should be in lua ?? Lua code is very dodgey to change - LoadWord, EncloseWord configurable? - dump text editor state to file, restore state -- help menu popup when for example in process buffer, on tile bar buffer and stuff like that - proper lister - ask user if he really wants to quit even though he has an unsaved buffer - popup window | we could just show ForceClose() in the titlebar