diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 77e8465..3681f63 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -450,18 +450,6 @@ bool GlobalCommand(Event event) { ToggleFullscreen(); } - if (Ctrl(SDLK_P)) { - Window *command_window = GetWindow(CommandWindowID); - if (command_window->visible) { - SetActiveWindow(GetLastActiveWindow()); - } else { - View *view = GetView(command_window->active_view); - SetActiveWindow(command_window->id); - Command_EvalLua(view, L"ListBuffers()"); - } - run_window_command = false; - } - if (Ctrl(SDLK_1)) { Window *window = GetLayoutWindow(0); if (window) SetActiveWindow(window->id); diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index a2a63bd..0863507 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -619,6 +619,27 @@ void Command_GotoNextInList(Window *window, Int line_offset = 1) { if (!opened) window->active_view = active_view; } +void Command_FuzzySort(View *view, String16 needle) { + Buffer *buffer = GetBuffer(view->active_buffer); + + Scratch scratch; + Array ratings = FuzzySearchLines(scratch, buffer, 0, buffer->line_starts.len, needle); + + Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap); + For(ratings) { + String16 s = GetLineStringWithoutNL(*buffer, it.index); + if (s.len == 0) continue; + IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s); + IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n"); + } + + Command_SelectEntireBuffer(view); + Command_Replace(view, GetString(*temp_buffer)); + + view->carets.len = 1; + view->carets[0] = MakeCaret({}); +} + void WindowCommand(Event event, Window *window, View *view) { ProfileFunction(); Buffer *buffer = GetBuffer(view->active_buffer); @@ -813,52 +834,15 @@ void WindowCommand(Event event, Window *window, View *view) { Command_GotoNextInList(window, 1); } - if (view->fuzzy_search && search) { - Scratch scratch; - String16 first_line_string = GetLineStringWithoutNL(*buffer, 0); - Array ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string); - - Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap); - IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string); - IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n"); - For(ratings) { - String16 s = GetLineStringWithoutNL(*buffer, it.index); - if (s.len == 0) continue; - IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s); - IKnowWhatImDoing_ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n"); - } - - Caret caret = view->carets[0]; - Command_SelectEntireBuffer(view); - Command_Replace(view, GetString(*temp_buffer)); - view->carets[0] = caret; - } - - if (view->fuzzy_search) { - if (Press(SDLK_RETURN)) { - Scratch scratch; - Buffer *buffer = GetBuffer(view->active_buffer); - Int line = PosToLine(*buffer, GetFront(view->carets[0])); - if (line == 0) line = 1; - - String16 string = GetLineStringWithoutNL(*buffer, line); - Open(string); - - // Clear text - Command_SelectRangeOneCursor(view, GetLineRangeWithoutNL(*buffer, 0)); - Command_Replace(view, {}); - } - } else { - if (CtrlShift(SDLK_RETURN)) { - Command_MoveCursorsToSide(view, DIR_LEFT); - Command_IdentedNewLine(view); - Command_Move(view, DIR_UP); - } else if (Ctrl(SDLK_RETURN)) { - Command_MoveCursorsToSide(view, DIR_RIGHT); - Command_IdentedNewLine(view); - } else if (Press(SDLK_RETURN)) { - Command_IdentedNewLine(view); - } + if (CtrlShift(SDLK_RETURN)) { + Command_MoveCursorsToSide(view, DIR_LEFT); + Command_IdentedNewLine(view); + Command_Move(view, DIR_UP); + } else if (Ctrl(SDLK_RETURN)) { + Command_MoveCursorsToSide(view, DIR_RIGHT); + Command_IdentedNewLine(view); + } else if (Press(SDLK_RETURN)) { + Command_IdentedNewLine(view); } if (Ctrl(SDLK_S)) { diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 56691ea..8f5f6d3 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -92,6 +92,19 @@ void Open(String16 path) { Open(string); } +int Lua_FuzzySort(lua_State *L) { + String string = lua_tostring(L, 1); + lua_pop(L, 1); + Scratch scratch; + String16 string16 = ToString16(scratch, string); + + WindowID window_id = GetLastActiveWindow(); + Window *window = GetWindow(window_id); + View *view = GetView(window->active_view); + Command_FuzzySort(view, string16); + return 0; +} + int Lua_AppendCmd(lua_State *L) { String string = lua_tostring(L, 1); lua_pop(L, 1); diff --git a/src/text_editor/lua_api_generated.cpp b/src/text_editor/lua_api_generated.cpp index 24fd839..df8db84 100644 --- a/src/text_editor/lua_api_generated.cpp +++ b/src/text_editor/lua_api_generated.cpp @@ -1,4 +1,5 @@ luaL_Reg LuaFunctions[] = { + {"FuzzySort", Lua_FuzzySort}, {"AppendCmd", Lua_AppendCmd}, {"NewCmd", Lua_NewCmd}, {"Kill", Lua_Kill}, diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index e67e41b..44ff23d 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -9,7 +9,6 @@ Array Windows = {}; WindowID NullWindowID; BufferID NullBufferID; ViewID NullViewID; -WindowID CommandWindowID; WindowID DebugWindowID; WindowID ConsoleWindowID; diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 390a84e..46fee8a 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -51,10 +51,6 @@ struct View { // window | view Caret main_caret_on_begin_frame; bool update_scroll; - - struct { - bool fuzzy_search : 1; - }; }; struct GotoCrumb { diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index b5160d9..6c49b32 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -193,30 +193,6 @@ void InitWindows() { SetVisibility(window_id, false); } - { - Window *w = CreateWindow(); - WindowID window_id = w->id; - w->draw_scrollbar = false; - w->draw_line_numbers = false; - w->visible = false; - w->invisible_when_inactive = true; - w->absolute_position = true; - w->dont_save_in_active_window_history = true; - w->deactivate_on_escape = true; - Buffer *b = CreateBuffer(sys_allocator, BuffCWD("+commands")); - View *v = CreateView(b->id); - v->fuzzy_search = true; - - w->active_view = v->id; - w->z = 1; - - Window *titlebar = CreateTitlebar(window_id); - titlebar->z = 1; - SetVisibility(window_id, false); - - CommandWindowID = window_id; - } - SetActiveWindow({0}); } @@ -286,26 +262,4 @@ void LayoutWindows() { window->document_rect = window->total_rect; } - - { - Window *window = GetWindow(CommandWindowID); - if (window->visible) { - Rect2 screen_rect = GetScreenRectF(); - - Vec2 size = GetSize(screen_rect); - - CutTop(&screen_rect, size.y * 0.05f); - CutLeft(&screen_rect, size.x * 0.2f); - CutRight(&screen_rect, size.x * 0.2f); - Rect2 r = CutTop(&screen_rect, FontLineSpacing * 30.f); - - window->total_rect = ToRect2I(r); - - Window *title_bar_window = GetWindow(window->title_bar_window); - title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window)); - title_bar_window->document_rect = title_bar_window->total_rect; - - window->document_rect = window->total_rect; - } - } } \ No newline at end of file diff --git a/src/text_editor/window_draw.cpp b/src/text_editor/window_draw.cpp index 180bea7..9bde1ba 100644 --- a/src/text_editor/window_draw.cpp +++ b/src/text_editor/window_draw.cpp @@ -211,21 +211,6 @@ void DrawWindow(Window *window, Event &event) { } } - if (view->fuzzy_search) { - Caret it = view->carets[0]; - Int front = GetFront(it); - XY fxy = PosToXY(*buffer, front); - if (fxy.line == 0) fxy.line += 1; - Vec2I w = XYToWorldPos(view, XYLine(fxy.line)); - w -= view->scroll; - w += window->document_rect.min; - Rect2 rect = { - {(float)window->total_rect.min.x, (float)w.y}, - {(float)window->total_rect.max.x, (float)w.y + (float)FontLineSpacing} - }; - DrawRectOutline(rect, ColorFuzzySearchLineHighlight); - } - EndProfileScope(); DrawVisibleText(window, color_text);