Command window opens files and move fuzzy search to view

This commit is contained in:
Krzosa Karol
2024-08-04 07:55:49 +02:00
parent b68b80f317
commit cc04fec1de
5 changed files with 12 additions and 9 deletions

View File

@@ -703,7 +703,7 @@ void WindowCommand(Event event, Window *window, View *view) {
}
// @todo: consider making this view command
if (window->fuzzy_search && search) {
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);
@@ -724,7 +724,7 @@ void WindowCommand(Event event, Window *window, View *view) {
view->carets[0] = caret;
}
if (window->fuzzy_search) {
if (view->fuzzy_search) {
if (Press(SDLK_RETURN)) {
Scratch scratch;
Buffer *buffer = GetBuffer(view->active_buffer);
@@ -732,7 +732,7 @@ void WindowCommand(Event event, Window *window, View *view) {
if (line == 0) line = 1;
String16 string = GetLineStringWithoutNL(*buffer, line);
EvalString(scratch, string);
Open(string);
// Clear text
Command_SelectRangeOneCursor(view, GetLineRangeWithoutNL(*buffer, 0));

View File

@@ -78,7 +78,7 @@ int LuaListOpenBuffers(lua_State *L) {
Scratch scratch;
Array<String> strings = {scratch};
For(Buffers) {
String string = Format(scratch, "open \"%.*s\"", FmtString(it.name));
String string = Format(scratch, "%.*s", FmtString(it.name));
Add(&strings, string);
}
String result = Merge(scratch, strings, "\n");

View File

@@ -53,6 +53,10 @@ struct View {
int underline_count;
Int underline_pos[2];
struct {
bool fuzzy_search : 1;
};
};
struct Window {
@@ -79,14 +83,12 @@ struct Window {
bool draw_scrollbar : 1;
bool draw_line_numbers : 1;
bool invisible_when_inactive : 1;
bool visible : 1;
bool absolute_position : 1;
bool is_title_bar : 1;
bool is_column : 1;
bool fuzzy_search : 1; // @todo: consider moving this to view and introducing view commands
bool execute_line : 1;
bool invisible_when_inactive : 1;
bool dont_save_in_active_window_history : 1;
bool deactivate_on_escape : 1;
};

View File

@@ -164,13 +164,14 @@ void InitWindows(View *null_view) {
w->draw_scrollbar = false;
w->draw_line_numbers = false;
w->visible = false;
w->fuzzy_search = true;
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, "*commands*");
View *v = CreateView(b->id);
v->fuzzy_search = true;
SetActiveView(w, v->id);
w->z = 1;

View File

@@ -181,7 +181,7 @@ void DrawWindow(Window *window) {
DrawRectOutline(rect, ColorText);
}
if (window->fuzzy_search) {
if (view->fuzzy_search) {
Caret it = view->carets[0];
Int front = GetFront(it);
XY fxy = PosToXY(*buffer, front);