Remove command window

This commit is contained in:
Krzosa Karol
2024-08-10 08:31:14 +02:00
parent a12a10ee0b
commit 90aaa375d0
8 changed files with 44 additions and 124 deletions

View File

@@ -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);

View File

@@ -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<FuzzyPair> 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<FuzzyPair> 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)) {

View File

@@ -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);

View File

@@ -1,4 +1,5 @@
luaL_Reg LuaFunctions[] = {
{"FuzzySort", Lua_FuzzySort},
{"AppendCmd", Lua_AppendCmd},
{"NewCmd", Lua_NewCmd},
{"Kill", Lua_Kill},

View File

@@ -9,7 +9,6 @@ Array<Window> Windows = {};
WindowID NullWindowID;
BufferID NullBufferID;
ViewID NullViewID;
WindowID CommandWindowID;
WindowID DebugWindowID;
WindowID ConsoleWindowID;

View File

@@ -51,10 +51,6 @@ struct View {
// window | view
Caret main_caret_on_begin_frame;
bool update_scroll;
struct {
bool fuzzy_search : 1;
};
};
struct GotoCrumb {

View File

@@ -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;
}
}
}

View File

@@ -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);