Hook code cleanup

This commit is contained in:
Krzosa Karol
2025-12-30 12:56:36 +01:00
parent ebf0f5de27
commit 5214ce61ac
4 changed files with 70 additions and 91 deletions

View File

@@ -11,7 +11,6 @@ How to go about search/replace, opening code and other considerations
Use session 2
- Need configs I can't change browser or vcvarsall currently, maybe syntax like :Set InternetBrowser "firefox"
- BUILD annoying: Console or use the other window / the window which is already being used
- Tutorial
- When jumping should center the view!!!

View File

@@ -402,7 +402,7 @@ BSet ExecBuild(String cmd) {
BSet main = GetBSet(LastActiveLayoutWindowID);
SelectRange(build.view, Range{});
ResetBuffer(build.buffer);
Exec(build.view->id, false, cmd, WorkDir); // NOTE: IN CASE WE MOVE THIS TO CONSOLE WINDOW, MAKE SURE TO SWITCH HERE the scrolling
Exec(build.view->id, true, cmd, WorkDir);
main.window->active_goto_list = build.view->id;
main.window->goto_list_pos = 0;
return build;
@@ -949,9 +949,6 @@ void Command_MakeFontSmaller() {
void Command_Open() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) {
return;
}
Open(FetchLoadWord(active.view));
} RegisterCommand(Command_Open, "ctrl-q");
@@ -1172,12 +1169,9 @@ void Command_InsertNewLineDown() {
} RegisterCommand(Command_InsertNewLineDown, "ctrl-enter");
void Command_NewLine() {
if (ActiveWindowID == CommandWindowID || ActiveWindowID == SearchWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
IdentedNewLine(active.view);
} RegisterCommand(Command_NewLine, "enter");
} RegisterCommand(Command_NewLine, "enter | shift-enter");
void Command_CreateCaretOnNextFind() {
BSet active = GetBSet(ActiveWindowID);

View File

@@ -1,32 +1,3 @@
void CommandWindowInit() {
Window *window = CreateWind();
CommandWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar"));
buffer->special = true;
View *view = CreateView(buffer->id);
view->special = true;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->draw_darker = true;
window->draw_line_highlight = true;
window->layout = false;
window->visible = false;
window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true;
window->jump_history = false;
}
void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {
Window *n = GetWindow(CommandWindowID);
Rect2I copy_rect = *rect;
if (!n->visible) {
rect = &copy_rect;
}
Int barsize = Clamp((Int)n->font->line_spacing*10, (Int)0, (Int)wx - 100);
n->document_rect = n->total_rect = CutBottom(rect, barsize);
}
int32_t FuzzyRate(String16 string, String16 with) {
ProfileFunction();
if (with.len == 0) return 0;
@@ -175,12 +146,39 @@ void OpenCommand(BSet active) {
Open(string);
}
void Command_OpenCommand() {
if (ActiveWindowID != CommandWindowID) {
return;
}
void Command_CommandWindowOpen() {
BSet active = GetBSet(ActiveWindowID);
BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id;
OpenCommand(active);
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");
}
void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {
Window *n = GetWindow(CommandWindowID);
Rect2I copy_rect = *rect;
if (!n->visible) {
rect = &copy_rect;
}
Int barsize = Clamp((Int)n->font->line_spacing*10, (Int)0, (Int)wx - 100);
n->document_rect = n->total_rect = CutBottom(rect, barsize);
}
void CommandWindowInit() {
Window *window = CreateWind();
CommandWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar"));
buffer->special = true;
View *view = CreateView(buffer->id);
view->special = true;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->draw_darker = true;
window->draw_line_highlight = true;
window->layout = false;
window->visible = false;
window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true;
window->jump_history = false;
AddHook(&view->hooks, "Open", "ctrl-q | enter", Command_CommandWindowOpen);
}

View File

@@ -1,34 +1,3 @@
void SearchWindowInit() {
Window *window = CreateWind();
SearchWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "search"));
buffer->special = true;
SearchBufferID = buffer->id;
View *view = CreateView(buffer->id);
view->special = true;
SearchViewID = view->id;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->draw_darker = true;
window->draw_line_highlight = false;
window->layout = false;
window->visible = false;
window->lose_visibility_on_escape = true;
window->jump_history = false;
}
void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
Window *n = GetWindow(SearchWindowID);
Rect2I copy_rect = *rect;
if (!n->visible) {
rect = &copy_rect;
}
Int barsize = GetExpandingBarSize(n);
n->document_rect = n->total_rect = CutBottom(rect, barsize);
n->line_numbers_rect = CutLeft(&n->document_rect, n->font->char_spacing * 6);
}
void Command_Search() {
BSet main = GetBSet(ActiveWindowID);
String16 string = {};
@@ -54,18 +23,12 @@ void SearchWindowFindNext(bool forward = true) {
}
void Command_SearchNextInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNextInSearch, "enter");
}
void Command_SearchPrevInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrevInSearch, "shift-enter");
}
void Command_SearchNext() {
SearchWindowFindNext(true);
@@ -96,15 +59,6 @@ void Command_SearchAll() {
set.window->visible = false;
} RegisterCommand(Command_SearchAll, "alt-f3");
void Command_SearchAllInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchAll();
BSet set = GetBSet(SearchWindowID);
set.window->visible = false;
} RegisterCommand(Command_SearchAllInSearch, "alt-enter");
void Command_ToggleCaseSensitiveSearch() {
SearchCaseSensitive = !SearchCaseSensitive;
} RegisterCommand(Command_ToggleCaseSensitiveSearch, "alt-c");
@@ -123,3 +77,37 @@ void SearchWindowUpdate() {
Find(main.view, seek, true);
}
}
void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
Window *n = GetWindow(SearchWindowID);
Rect2I copy_rect = *rect;
if (!n->visible) {
rect = &copy_rect;
}
Int barsize = GetExpandingBarSize(n);
n->document_rect = n->total_rect = CutBottom(rect, barsize);
n->line_numbers_rect = CutLeft(&n->document_rect, n->font->char_spacing * 6);
}
void SearchWindowInit() {
Window *window = CreateWind();
SearchWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "search"));
buffer->special = true;
SearchBufferID = buffer->id;
View *view = CreateView(buffer->id);
view->special = true;
SearchViewID = view->id;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->draw_darker = true;
window->draw_line_highlight = false;
window->layout = false;
window->visible = false;
window->lose_visibility_on_escape = true;
window->jump_history = false;
AddHook(&view->hooks, "SearchAll", "alt-enter", Command_SearchAll);
AddHook(&view->hooks, "SearchPrevInSearch", "shift-enter", Command_SearchPrevInSearch);
AddHook(&view->hooks, "SearchNextInSearch", "enter", Command_SearchNextInSearch);
}