Compare commits
4 Commits
f33c9873d0
...
5ab20ce8ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ab20ce8ab | ||
|
|
61fc0cd339 | ||
|
|
3864060699 | ||
|
|
db06c783a9 |
@@ -1142,7 +1142,7 @@ API void InitBuffer(Allocator allocator, Buffer *buffer, BufferID id = {}, Strin
|
||||
API void DeinitBuffer(Buffer *buffer) {
|
||||
Allocator allocator = buffer->line_starts.allocator;
|
||||
Dealloc(allocator, buffer->data);
|
||||
Dealloc(&buffer->hooks);
|
||||
Dealloc(&buffer->commands);
|
||||
Dealloc(&buffer->line_starts);
|
||||
DeallocHistoryArray(&buffer->undo_stack);
|
||||
DeallocHistoryArray(&buffer->redo_stack);
|
||||
@@ -1530,7 +1530,6 @@ void ReopenBuffer(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
if (buffer->is_dir) {
|
||||
ResetBuffer(buffer);
|
||||
RawAppendf(buffer, "..\n");
|
||||
for (FileIter it = IterateFiles(scratch, buffer->name); IsValid(it); Advance(&it)) {
|
||||
RawAppendf(buffer, "%S\n", it.filename);
|
||||
}
|
||||
@@ -1552,13 +1551,8 @@ void ReopenBuffer(Buffer *buffer) {
|
||||
void SaveBuffer(Buffer *buffer) {
|
||||
ProfileFunction();
|
||||
|
||||
For (GlobalHooks) {
|
||||
if (it.kind == HookKind_BeforeSavingBuffer) {
|
||||
ProfileScopeEx(it.name);
|
||||
HookParam param = {};
|
||||
param.buffer = buffer;
|
||||
it.function(param);
|
||||
}
|
||||
if (TrimTrailingWhitespace) {
|
||||
TrimWhitespace(buffer, false);
|
||||
}
|
||||
|
||||
Scratch scratch;
|
||||
|
||||
@@ -167,7 +167,7 @@ void UIMessagef(const char *fmt, ...) {
|
||||
NextActiveWindowID = main.window->id;
|
||||
RawAppendf(main.buffer, "\n %S\n :Close\n", string);
|
||||
main.view->carets[0] = FindNext(main.buffer, u":Close", MakeCaret(0));
|
||||
AddCommand(&main.view->hooks, "Close", "escape | enter", [](HookParam param){
|
||||
AddCommand(&main.view->commands, "Close", "escape | enter", [](){
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Close(active.buffer->id);
|
||||
});
|
||||
@@ -223,7 +223,7 @@ void CenterView(WindowID window) {
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_CenterView(HookParam param) {
|
||||
void CMD_CenterView() {
|
||||
CenterView(PrimaryWindowID);
|
||||
} RegisterCommand(CMD_CenterView, "");
|
||||
|
||||
@@ -291,12 +291,6 @@ void TrimWhitespace(Buffer *buffer, bool trim_lines_with_caret) {
|
||||
view->update_scroll = false;
|
||||
}
|
||||
|
||||
void HOOK_TrimTrailingWhitespace(HookParam param) {
|
||||
if (TrimTrailingWhitespace) {
|
||||
TrimWhitespace(param.buffer, false);
|
||||
}
|
||||
} RegisterHook(HOOK_TrimTrailingWhitespace, HookKind_BeforeSavingBuffer, "", "Cleans trailing whitespace before saving to file");
|
||||
|
||||
void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) {
|
||||
Scratch scratch;
|
||||
|
||||
@@ -342,7 +336,7 @@ void ApplyFormattingTool(Buffer *buffer, String tool) {
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_FormatSelection(HookParam param) {
|
||||
void CMD_FormatSelection() {
|
||||
Scratch scratch;
|
||||
BSet primary = GetBSet(PrimaryWindowID);
|
||||
|
||||
@@ -477,18 +471,7 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) {
|
||||
return main;
|
||||
}
|
||||
|
||||
BSet ExecBuild(String cmd) {
|
||||
BSet build = GetBSet(BuildWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
SelectRange(build.view, Range{});
|
||||
ResetBuffer(build.buffer);
|
||||
Exec(build.view->id, true, cmd, WorkDir);
|
||||
main.window->active_goto_list = build.view->id;
|
||||
main.window->goto_list_pos = 0;
|
||||
return build;
|
||||
}
|
||||
|
||||
void CMD_SaveAll(HookParam param) {
|
||||
void CMD_SaveAll() {
|
||||
For(Buffers) {
|
||||
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
|
||||
if (it->file_mod_time && it->dirty) {
|
||||
@@ -497,23 +480,12 @@ void CMD_SaveAll(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
|
||||
|
||||
void CMD_Build(HookParam param) {
|
||||
CMD_SaveAll({});
|
||||
#if OS_WINDOWS
|
||||
ExecBuild("build.bat");
|
||||
#else
|
||||
ExecBuild("sh build.sh");
|
||||
#endif
|
||||
BSet main = GetBSet(BuildWindowID);
|
||||
main.window->visible = true;
|
||||
} RegisterCommand(CMD_Build, "f1", "Run build.sh or build.bat in working directory, output is printed in a popup console and a special build buffer");
|
||||
|
||||
void CMD_GotoNextInList(HookParam param) {
|
||||
void CMD_GotoNextInList() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
GotoNextInList(main.window, 1);
|
||||
} RegisterCommand(CMD_GotoNextInList, "ctrl-e", "For example: when jumping from build panel to build error, a jump point is setup, user can click this button to go over to the next compiler error");
|
||||
|
||||
void CMD_GotoPrevInList(HookParam param) {
|
||||
void CMD_GotoPrevInList() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
GotoNextInList(main.window, -1);
|
||||
} RegisterCommand(CMD_GotoPrevInList, "alt-e", "For example: when jumping from build panel to build error, a jump point is setup, user can click this button to go over to the previous compiler error");
|
||||
@@ -592,8 +564,8 @@ void Set(String string) {
|
||||
return;
|
||||
}
|
||||
|
||||
Hook *cmd = NULL;
|
||||
For (GlobalHooks) {
|
||||
Command *cmd = NULL;
|
||||
For (GlobalCommands) {
|
||||
if (it.name == name) {
|
||||
cmd = ⁢
|
||||
break;
|
||||
@@ -774,7 +746,7 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
|
||||
SetFuzzy(view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
ResetBuffer(buffer);
|
||||
RawAppendf(buffer, "\n..\n");
|
||||
RawAppendf(buffer, "\n");
|
||||
for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) {
|
||||
RawAppendf(buffer, "%S\n", it.filename);
|
||||
}
|
||||
@@ -823,23 +795,23 @@ BSet Open(String16 path, ResolveOpenMeta meta) {
|
||||
return Open(string, meta);
|
||||
}
|
||||
|
||||
void CMD_Save(HookParam param) {
|
||||
void CMD_Save() {
|
||||
BSet active = GetBSet(PrimaryWindowID);
|
||||
SaveBuffer(active.buffer);
|
||||
} RegisterCommand(CMD_Save, "ctrl-s", "Save buffer currently open in the last primary window");
|
||||
|
||||
void CMD_Reopen(HookParam param) {
|
||||
void CMD_Reopen() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
ReopenBuffer(main.buffer);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Reopen, "");
|
||||
|
||||
void CMD_New(HookParam param) {
|
||||
void CMD_New() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
New(main.window, "");
|
||||
} RegisterCommand(CMD_New, "ctrl-n", "Open a new buffer with automatically generated name, use :Rename");
|
||||
|
||||
void CMD_ToggleFullscreen(HookParam param) {
|
||||
void CMD_ToggleFullscreen() {
|
||||
if (IsInFullscreen) {
|
||||
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
|
||||
SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY);
|
||||
@@ -856,7 +828,7 @@ void CMD_ToggleFullscreen(HookParam param) {
|
||||
IsInFullscreen = !IsInFullscreen;
|
||||
} RegisterCommand(CMD_ToggleFullscreen, "f11");
|
||||
|
||||
void CMD_SetWorkDirHere(HookParam param) {
|
||||
void CMD_SetWorkDirHere() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
SetWorkDirHere(GetDir(main.buffer));
|
||||
} RegisterCommand(CMD_SetWorkDirHere, "", "Sets work directory to the directory of the current buffer, it also renames couple special buffers to make them accomodate the new WorkDir");
|
||||
@@ -913,38 +885,27 @@ void OpenCode(String dir) {
|
||||
CoResume(data);
|
||||
}
|
||||
|
||||
void CMD_OpenCode(HookParam param) {
|
||||
void CMD_OpenCode() {
|
||||
OpenCode(WorkDir);
|
||||
} RegisterCommand(CMD_OpenCode, "", "Open all code files in current WorkDir, the code files are determined through NonCodePatterns_EndsWith config variable list");
|
||||
|
||||
void CMD_KillProcess(HookParam param) {
|
||||
void CMD_KillProcess() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
KillProcess(main.view);
|
||||
} RegisterCommand(CMD_KillProcess, "", "Kill process in the last active primary window");
|
||||
|
||||
void CMD_CloseWindow(HookParam param) {
|
||||
void CMD_CloseWindow() {
|
||||
Close(PrimaryWindowID);
|
||||
} RegisterCommand(CMD_CloseWindow, "", "Close the last active primary window");
|
||||
|
||||
void AddCommand(Array<Hook> *arr, String name, String binding, HookFunction *function) {
|
||||
Hook hook = {};
|
||||
hook.name = name;
|
||||
hook.binding = binding;
|
||||
hook.function = function;
|
||||
hook.trigger = ParseKeyCached(binding);
|
||||
hook.docs = "Not listing hooks anywhere currently, maybe should change!!";
|
||||
Add(arr, hook);
|
||||
}
|
||||
|
||||
void AddHook(Array<Hook> *arr, HookKind kind, String name, String binding, HookFunction *function) {
|
||||
Hook hook = {};
|
||||
hook.kind = kind;
|
||||
hook.name = name;
|
||||
hook.binding = binding;
|
||||
hook.function = function;
|
||||
hook.trigger = ParseKeyCached(binding);
|
||||
hook.docs = "Not listing hooks anywhere currently, maybe should change!!";
|
||||
Add(arr, hook);
|
||||
void AddCommand(Array<Command> *arr, String name, String binding, CMDFunction *function) {
|
||||
Command cmd = {};
|
||||
cmd.name = name;
|
||||
cmd.binding = binding;
|
||||
cmd.function = function;
|
||||
cmd.trigger = ParseKeyCached(binding);
|
||||
cmd.docs = "Not listing commands attached to things anywhere currently, maybe should change?";
|
||||
Add(arr, cmd);
|
||||
}
|
||||
|
||||
void Coro_Rename(mco_coro *co) {
|
||||
@@ -956,8 +917,8 @@ void Coro_Rename(mco_coro *co) {
|
||||
|
||||
main.view->carets[0] = FindNext(main.buffer, u"]", MakeCaret(0));
|
||||
main.view->carets[0].range.max = main.view->carets[0].range.min;
|
||||
AddCommand(&main.view->hooks, "Rename", "enter", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Rename";});
|
||||
AddCommand(&main.view->hooks, "Cancel", "escape", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
AddCommand(&main.view->commands, "Rename", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Rename";});
|
||||
AddCommand(&main.view->commands, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
String result = "Cancel";
|
||||
for (;;) {
|
||||
if (main.window->active_view != main.view->id || (main.window->id != PrimaryWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
@@ -986,7 +947,7 @@ void Coro_Rename(mco_coro *co) {
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_Rename(HookParam param) {
|
||||
void CMD_Rename() {
|
||||
CoRemove("Coro_Rename");
|
||||
CoData *data = CoAdd(Coro_Rename);
|
||||
CoResume(data);
|
||||
@@ -1002,9 +963,9 @@ String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
||||
)==", question);
|
||||
main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0));
|
||||
main.view->carets[0].range.min = main.view->carets[0].range.max;
|
||||
AddCommand(&main.view->hooks, "Yes", "enter", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Yes";});
|
||||
AddCommand(&main.view->hooks, "No", "", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "No";});
|
||||
AddCommand(&main.view->hooks, "Cancel", "escape", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
AddCommand(&main.view->commands, "Yes", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Yes";});
|
||||
AddCommand(&main.view->commands, "No", "", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "No";});
|
||||
AddCommand(&main.view->commands, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
String result = "Cancel";
|
||||
for (;;) {
|
||||
if (main.window->active_view != main.view->id || (main.window->id != PrimaryWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
@@ -1062,13 +1023,13 @@ void Coro_Close(mco_coro *co) {
|
||||
} ElseInvalidCodepath();
|
||||
}
|
||||
|
||||
void CMD_Close(HookParam param) {
|
||||
void CMD_Close() {
|
||||
CoRemove("Coro_Close");
|
||||
CoData *data = CoAdd(Coro_Close);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_Close, "ctrl-w", "Close open view in the last active primary window");
|
||||
|
||||
void CMD_DeleteFile(HookParam param) {
|
||||
void CMD_DeleteFile() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String buffer_name = main.buffer->name;
|
||||
DeleteFile(main.buffer->name);
|
||||
@@ -1109,105 +1070,96 @@ String Coro_CloseAllEx(mco_coro *co) {
|
||||
return "Yes";
|
||||
}
|
||||
|
||||
void CMD_QuitWithoutSaving() {
|
||||
#ifdef PLUGIN_REMEDYBG
|
||||
QuitDebugger();
|
||||
#endif
|
||||
AppIsRunning = false;
|
||||
} RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory");
|
||||
|
||||
void Coro_Quit(mco_coro *co) {
|
||||
String res = Coro_CloseAllEx(co);
|
||||
if (res != "Cancel") {
|
||||
For (GlobalHooks) {
|
||||
if (it.kind == HookKind_AppQuit) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
}
|
||||
}
|
||||
AppIsRunning = false;
|
||||
CMD_QuitWithoutSaving();
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_Quit(HookParam param) {
|
||||
void CMD_Quit() {
|
||||
CoRemove("Coro_Quit");
|
||||
CoData *data = CoAdd(Coro_Quit);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_Quit, "", "Ask user which files he would like to save and exit");
|
||||
|
||||
void CMD_QuitWithoutSaving(HookParam param) {
|
||||
For (GlobalHooks) {
|
||||
if (it.kind == HookKind_AppQuit) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
}
|
||||
}
|
||||
AppIsRunning = false;
|
||||
} RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory");
|
||||
|
||||
void Coro_CloseAll(mco_coro *co) {
|
||||
Coro_CloseAllEx(co);
|
||||
}
|
||||
|
||||
void CMD_CloseAll(HookParam param) {
|
||||
void CMD_CloseAll() {
|
||||
CoRemove("Coro_CloseAll");
|
||||
CoData *data = CoAdd(Coro_CloseAll);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_CloseAll, "", "Ask user which files to save and close all open normal views and buffers");
|
||||
|
||||
void CMD_JumpPrev(HookParam param) {
|
||||
void CMD_JumpPrev() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
JumpToLastValidView(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_JumpPrev, "ctrl-tab", "Go to the previous open view in primary window");
|
||||
|
||||
void CMD_Prev(HookParam param) {
|
||||
void CMD_Prev() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpBack(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Prev, "alt-q | mousex1", "Go to previous position (either previous view that was open or caret position) in the primary window");
|
||||
|
||||
void CMD_Next(HookParam param) {
|
||||
void CMD_Next() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpForward(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Next, "alt-shift-q | mousex2", "Go to next position, after backtracking, in the primary window");
|
||||
|
||||
void CMD_OpenUpFolder(HookParam param) {
|
||||
void CMD_OpenUpFolder() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String name = ChopLastSlash(main.buffer->name);
|
||||
Open(name);
|
||||
} RegisterCommand(CMD_OpenUpFolder, "ctrl-o", "Open current's file directory or up directory in other cases");
|
||||
|
||||
void CMD_EncloseLine(HookParam param) {
|
||||
void CMD_EncloseLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
EncloseLine(active.view);
|
||||
} RegisterCommand(CMD_EncloseLine, "ctrl-l", "Select the entire line on which your caret is placed");
|
||||
|
||||
void CMD_SelectAll(HookParam param) {
|
||||
void CMD_SelectAll() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SelectEntireBuffer(active.view);
|
||||
active.view->update_scroll = false;
|
||||
} RegisterCommand(CMD_SelectAll, "ctrl-a", "Select the entire buffer");
|
||||
|
||||
void CMD_Redo(HookParam param) {
|
||||
void CMD_Redo() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
RedoEdit(active.buffer, &active.view->carets);
|
||||
} RegisterCommand(CMD_Redo, "ctrl-shift-z", "Redo after undoing changes to the buffer");
|
||||
|
||||
void CMD_Undo(HookParam param) {
|
||||
void CMD_Undo() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
UndoEdit(active.buffer, &active.view->carets);
|
||||
} RegisterCommand(CMD_Undo, "ctrl-z", "Undo last change you made to the buffer");
|
||||
|
||||
void CMD_MakeFontLarger(HookParam param) {
|
||||
void CMD_MakeFontLarger() {
|
||||
FontSize += 1;
|
||||
ReloadFont(PathToFont, (U32)FontSize);
|
||||
} RegisterCommand(CMD_MakeFontLarger, "ctrl-equals", "Increase the font size");
|
||||
|
||||
void CMD_MakeFontSmaller(HookParam param) {
|
||||
void CMD_MakeFontSmaller() {
|
||||
if (FontSize > 4) {
|
||||
FontSize -= 1;
|
||||
ReloadFont(PathToFont, (U32)FontSize);
|
||||
}
|
||||
} RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus", "Decrease the font size");
|
||||
|
||||
void CMD_OpenLoadWord(HookParam param) {
|
||||
void CMD_OpenLoadWord() {
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 load_word = FetchLoadWord(active.view);
|
||||
@@ -1218,210 +1170,210 @@ void CMD_OpenLoadWord(HookParam param) {
|
||||
Open(load_word);
|
||||
} RegisterCommand(CMD_OpenLoadWord, "ctrl-q | f12", "Open a link under the caret (file link, url, command) or open the selection");
|
||||
|
||||
void CMD_KillSelectedLines(HookParam param) {
|
||||
void CMD_KillSelectedLines() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
KillSelectedLines(active.view);
|
||||
} RegisterCommand(CMD_KillSelectedLines, "ctrl-shift-k");
|
||||
|
||||
void CMD_IndentSelectedLines(HookParam param) {
|
||||
void CMD_IndentSelectedLines() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
IndentSelectedLines(active.view);
|
||||
} RegisterCommand(CMD_IndentSelectedLines, "ctrl-rightbracket | tab");
|
||||
|
||||
void CMD_DedentSelectedLines(HookParam param) {
|
||||
void CMD_DedentSelectedLines() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
IndentSelectedLines(active.view, true);
|
||||
} RegisterCommand(CMD_DedentSelectedLines, "ctrl-leftbracket | shift-tab");
|
||||
|
||||
void CMD_DuplicateLineDown(HookParam param) {
|
||||
void CMD_DuplicateLineDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
DuplicateLine(active.view, DIR_DOWN);
|
||||
} RegisterCommand(CMD_DuplicateLineDown, "ctrl-alt-down");
|
||||
|
||||
void CMD_CreateCursorDown(HookParam param) {
|
||||
void CMD_CreateCursorDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
CreateCursorVertical(active.view, DIR_DOWN);
|
||||
} RegisterCommand(CMD_CreateCursorDown, "alt-shift-down");
|
||||
|
||||
void CMD_SelectDownToEmptyLine(HookParam param) {
|
||||
void CMD_SelectDownToEmptyLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectDownToEmptyLine, "ctrl-shift-down");
|
||||
|
||||
void CMD_MoveLineDown(HookParam param) {
|
||||
void CMD_MoveLineDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCaretsLine(active.view, DIR_DOWN);
|
||||
} RegisterCommand(CMD_MoveLineDown, "alt-down");
|
||||
|
||||
void CMD_MoveDownToEmptyLine(HookParam param) {
|
||||
void CMD_MoveDownToEmptyLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED);
|
||||
} RegisterCommand(CMD_MoveDownToEmptyLine, "ctrl-down");
|
||||
|
||||
void CMD_SelectDown(HookParam param) {
|
||||
void CMD_SelectDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectDown, "shift-down");
|
||||
|
||||
void CMD_MoveDown(HookParam param) {
|
||||
void CMD_MoveDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_DOWN);
|
||||
} RegisterCommand(CMD_MoveDown, "down");
|
||||
|
||||
void CMD_DuplicateLineUp(HookParam param) {
|
||||
void CMD_DuplicateLineUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
DuplicateLine(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_DuplicateLineUp, "ctrl-alt-up");
|
||||
|
||||
void CMD_CreateCursorUp(HookParam param) {
|
||||
void CMD_CreateCursorUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
CreateCursorVertical(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_CreateCursorUp, "alt-shift-up");
|
||||
|
||||
void CMD_SelectUpToEmptyLine(HookParam param) {
|
||||
void CMD_SelectUpToEmptyLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectUpToEmptyLine, "ctrl-shift-up");
|
||||
|
||||
void CMD_MoveLineUp(HookParam param) {
|
||||
void CMD_MoveLineUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCaretsLine(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_MoveLineUp, "alt-up");
|
||||
|
||||
void CMD_MoveUpToEmptyLine(HookParam param) {
|
||||
void CMD_MoveUpToEmptyLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_UP, CTRL_PRESSED);
|
||||
} RegisterCommand(CMD_MoveUpToEmptyLine, "ctrl-up");
|
||||
|
||||
void CMD_SelectUp(HookParam param) {
|
||||
void CMD_SelectUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectUp, "shift-up");
|
||||
|
||||
void CMD_MoveUp(HookParam param) {
|
||||
void CMD_MoveUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_MoveUp, "up");
|
||||
|
||||
void CMD_BoundarySelectLeft(HookParam param) {
|
||||
void CMD_BoundarySelectLeft() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_BoundarySelectLeft, "ctrl-shift-left");
|
||||
|
||||
void CMD_BoundaryMoveLeft(HookParam param) {
|
||||
void CMD_BoundaryMoveLeft() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED);
|
||||
} RegisterCommand(CMD_BoundaryMoveLeft, "ctrl-left");
|
||||
|
||||
void CMD_SelectLeft(HookParam param) {
|
||||
void CMD_SelectLeft() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectLeft, "shift-left");
|
||||
|
||||
void CMD_FocusLeftWindow(HookParam param) {
|
||||
void CMD_FocusLeftWindow() {
|
||||
NextActiveWindowID = SwitchWindow(DIR_LEFT)->id;
|
||||
} RegisterCommand(CMD_FocusLeftWindow, "alt-left");
|
||||
|
||||
void CMD_MoveLeft(HookParam param) {
|
||||
void CMD_MoveLeft() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_LEFT);
|
||||
} RegisterCommand(CMD_MoveLeft, "left");
|
||||
|
||||
void CMD_BoundarySelectRight(HookParam param) {
|
||||
void CMD_BoundarySelectRight() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_BoundarySelectRight, "ctrl-shift-right");
|
||||
|
||||
void CMD_BoundaryMoveRight(HookParam param) {
|
||||
void CMD_BoundaryMoveRight() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED);
|
||||
} RegisterCommand(CMD_BoundaryMoveRight, "ctrl-right");
|
||||
|
||||
void CMD_SelectRight(HookParam param) {
|
||||
void CMD_SelectRight() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectRight, "shift-right");
|
||||
|
||||
void CMD_FocusRightWindow(HookParam param) {
|
||||
void CMD_FocusRightWindow() {
|
||||
NextActiveWindowID = SwitchWindow(DIR_RIGHT)->id;
|
||||
} RegisterCommand(CMD_FocusRightWindow, "alt-right");
|
||||
|
||||
void CMD_MoveRight(HookParam param) {
|
||||
void CMD_MoveRight() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCarets(active.view, DIR_RIGHT);
|
||||
} RegisterCommand(CMD_MoveRight, "right");
|
||||
|
||||
void CMD_MoveUpAPage(HookParam param) {
|
||||
void CMD_MoveUpAPage() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorByPageSize(active.window, DIR_UP);
|
||||
} RegisterCommand(CMD_MoveUpAPage, "pageup");
|
||||
|
||||
void CMD_SelectUpPage(HookParam param) {
|
||||
void CMD_SelectUpPage() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectUpPage, "shift-pageup");
|
||||
|
||||
void CMD_MoveToStart(HookParam param) {
|
||||
void CMD_MoveToStart() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SelectRange(active.view, MakeRange(0));
|
||||
} RegisterCommand(CMD_MoveToStart, "ctrl-pageup");
|
||||
|
||||
void CMD_SelectDownPage(HookParam param) {
|
||||
void CMD_SelectDownPage() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectDownPage, "shift-pagedown");
|
||||
|
||||
void CMD_MoveToEnd(HookParam param) {
|
||||
void CMD_MoveToEnd() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SelectRange(active.view, MakeRange(active.buffer->len));
|
||||
} RegisterCommand(CMD_MoveToEnd, "ctrl-pagedown");
|
||||
|
||||
void CMD_MoveDownPage(HookParam param) {
|
||||
void CMD_MoveDownPage() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorByPageSize(active.window, DIR_DOWN);
|
||||
} RegisterCommand(CMD_MoveDownPage, "pagedown");
|
||||
|
||||
void CMD_SelectToLineStart(HookParam param) {
|
||||
void CMD_SelectToLineStart() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectToLineStart, "shift-home");
|
||||
|
||||
void CMD_MoveToLineStart(HookParam param) {
|
||||
void CMD_MoveToLineStart() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorToSide(active.view, DIR_LEFT);
|
||||
} RegisterCommand(CMD_MoveToLineStart, "home");
|
||||
|
||||
void CMD_MoveToLineEnd(HookParam param) {
|
||||
void CMD_MoveToLineEnd() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorToSide(active.view, DIR_RIGHT);
|
||||
} RegisterCommand(CMD_MoveToLineEnd, "end");
|
||||
|
||||
void CMD_SelectToLineEnd(HookParam param) {
|
||||
void CMD_SelectToLineEnd() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_SelectToLineEnd, "shift-end");
|
||||
|
||||
void CMD_DeleteCharacter(HookParam param) {
|
||||
void CMD_DeleteCharacter() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Delete(active.view, DIR_LEFT);
|
||||
} RegisterCommand(CMD_DeleteCharacter, "shift-backspace | backspace");
|
||||
|
||||
void CMD_DeleteBoundary(HookParam param) {
|
||||
void CMD_DeleteBoundary() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Delete(active.view, DIR_LEFT, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_DeleteBoundary, "ctrl-backspace");
|
||||
|
||||
void CMD_DeleteForward(HookParam param) {
|
||||
void CMD_DeleteForward() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Delete(active.view, DIR_RIGHT);
|
||||
} RegisterCommand(CMD_DeleteForward, "shift-delete | delete");
|
||||
|
||||
void CMD_DeleteForwardBoundary(HookParam param) {
|
||||
void CMD_DeleteForwardBoundary() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Delete(active.view, DIR_RIGHT, SHIFT_PRESS);
|
||||
} RegisterCommand(CMD_DeleteForwardBoundary, "ctrl-delete");
|
||||
|
||||
void CMD_InsertNewLineUp(HookParam param) {
|
||||
void CMD_InsertNewLineUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
MoveCursorToSide(active.view, DIR_LEFT);
|
||||
@@ -1429,19 +1381,19 @@ void CMD_InsertNewLineUp(HookParam param) {
|
||||
MoveCarets(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_InsertNewLineUp, "ctrl-shift-enter");
|
||||
|
||||
void CMD_InsertNewLineDown(HookParam param) {
|
||||
void CMD_InsertNewLineDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
MoveCursorToSide(active.view, DIR_RIGHT);
|
||||
IndentedNewLine(active.view);
|
||||
} RegisterCommand(CMD_InsertNewLineDown, "ctrl-enter");
|
||||
|
||||
void CMD_NewLine(HookParam param) {
|
||||
void CMD_NewLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
IndentedNewLine(active.view);
|
||||
} RegisterCommand(CMD_NewLine, "enter | shift-enter");
|
||||
|
||||
void CMD_CreateCaretOnNextFind(HookParam param) {
|
||||
void CMD_CreateCaretOnNextFind() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 string = GetString(active.buffer, active.view->carets[0].range);
|
||||
Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
|
||||
@@ -1449,17 +1401,17 @@ void CMD_CreateCaretOnNextFind(HookParam param) {
|
||||
MergeCarets(active.buffer, &active.view->carets);
|
||||
} RegisterCommand(CMD_CreateCaretOnNextFind, "ctrl-d");
|
||||
|
||||
void CMD_FocusWindow1(HookParam param) {
|
||||
void CMD_FocusWindow1() {
|
||||
NextActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id;
|
||||
} RegisterCommand(CMD_FocusWindow1, "ctrl-1");
|
||||
|
||||
void CMD_FocusWindow2(HookParam param) {
|
||||
void CMD_FocusWindow2() {
|
||||
Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID));
|
||||
Vec2I p = GetSideOfWindow(first, DIR_RIGHT);
|
||||
NextActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id;
|
||||
} RegisterCommand(CMD_FocusWindow2, "ctrl-2");
|
||||
|
||||
void CMD_FocusWindow3(HookParam param) {
|
||||
void CMD_FocusWindow3() {
|
||||
Window *first = GetOverlappingWindow({0,0});
|
||||
if (first) {
|
||||
Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT));
|
||||
@@ -1472,11 +1424,11 @@ void CMD_FocusWindow3(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_FocusWindow3, "ctrl-3");
|
||||
|
||||
void CMD_NewWindow(HookParam param) {
|
||||
void CMD_NewWindow() {
|
||||
CreateWind();
|
||||
} RegisterCommand(CMD_NewWindow, "ctrl-backslash");
|
||||
|
||||
void CMD_ClearCarets(HookParam param) {
|
||||
void CMD_ClearCarets() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
active.view->carets.len = 1;
|
||||
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
|
||||
@@ -1510,8 +1462,8 @@ void Coro_ReplaceAll(mco_coro *co) {
|
||||
|
||||
Caret field_seek = FindNext(main.buffer, u"for::", MakeCaret(0));
|
||||
main.view->carets[0] = FindNext(main.buffer, string, field_seek);
|
||||
AddCommand(&main.view->hooks, "Submit", "enter", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Submit";});
|
||||
AddCommand(&main.view->hooks, "Cancel", "escape", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
AddCommand(&main.view->commands, "Submit", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Submit";});
|
||||
AddCommand(&main.view->commands, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
|
||||
String result = "Cancel";
|
||||
for (;;) {
|
||||
@@ -1543,8 +1495,8 @@ void Coro_ReplaceAll(mco_coro *co) {
|
||||
|
||||
Caret field_seek = FindNext(main.buffer, u"with::", MakeCaret(0));
|
||||
main.view->carets[0] = MakeCaret(main.buffer->len, field_seek.range.max);
|
||||
AddCommand(&main.view->hooks, "Submit", "enter", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Submit";});
|
||||
AddCommand(&main.view->hooks, "Cancel", "escape", [](HookParam param){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
AddCommand(&main.view->commands, "Submit", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Submit";});
|
||||
AddCommand(&main.view->commands, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||
String result = "Cancel";
|
||||
for (;;) {
|
||||
if (main.window->active_view != main.view->id || (main.window->id != PrimaryWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
@@ -1581,14 +1533,50 @@ void Coro_ReplaceAll(mco_coro *co) {
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_ReplaceAll(HookParam param) {
|
||||
void CMD_ReplaceAll() {
|
||||
CoRemove("Coro_ReplaceAll");
|
||||
CoData *data = CoAdd(Coro_ReplaceAll);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_ReplaceAll, "ctrl-shift-r", "Search and replace over the entire project, you need to select a text with format like this 'FindAnd@>ReplaceWith' and executing the command will change all occurences of FindAnd to ReplaceWith");
|
||||
|
||||
struct SearchProjectParams {
|
||||
String16 needle;
|
||||
BufferID buffer;
|
||||
};
|
||||
|
||||
void UpdateSearchProjectView(HookParam param) {
|
||||
void Coro_SearchProject(mco_coro *co) {
|
||||
SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx;
|
||||
|
||||
Array<BufferID> buffers = {CoCurr->arena};
|
||||
For (Buffers) {
|
||||
Add(&buffers, it->id);
|
||||
}
|
||||
|
||||
ForItem (id, buffers) {
|
||||
Buffer *it = GetBuffer(id, NULL);
|
||||
if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
Scratch scratch;
|
||||
Array<Caret> occurences = FindAll(scratch, it, param->needle);
|
||||
Buffer *out_buffer = GetBuffer(param->buffer);
|
||||
ForItem (caret, occurences) {
|
||||
Int pos = caret.range.min;
|
||||
Int line = PosToLine(it, pos);
|
||||
Range range = GetLineRangeWithoutNL(it, line);
|
||||
Int column = pos - range.min;
|
||||
String16 line_string = GetString(it, range);
|
||||
String line_string8 = ToString(scratch, line_string);
|
||||
RawAppendf(out_buffer, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
|
||||
}
|
||||
}
|
||||
CoYield(co);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSearchProjectView() {
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
||||
@@ -1616,7 +1604,7 @@ void UpdateSearchProjectView(HookParam param) {
|
||||
}
|
||||
}
|
||||
|
||||
void CMD_SearchProject(HookParam param) {
|
||||
void CMD_SearchProject() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String16 string = {};
|
||||
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
|
||||
@@ -1627,7 +1615,7 @@ void CMD_SearchProject(HookParam param) {
|
||||
Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID);
|
||||
View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
|
||||
view->special = true;
|
||||
AddCommand(&view->hooks, "Open", "ctrl-q | enter | f12", [](HookParam param) {
|
||||
AddCommand(&view->commands, "Open", "ctrl-q | enter | f12", []() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
NextActiveWindowID = main.window->id;
|
||||
@@ -1636,7 +1624,7 @@ void CMD_SearchProject(HookParam param) {
|
||||
main.window->goto_list_pos = active.view->carets[0].range.min;
|
||||
Open(string);
|
||||
});
|
||||
AddHook(&view->hooks, HookKind_AppUpdate, "UpdateSearchProjectView", "", UpdateSearchProjectView);
|
||||
view->update_hook = UpdateSearchProjectView;
|
||||
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
|
||||
if (string.len) {
|
||||
Replace(view, string);
|
||||
|
||||
@@ -87,17 +87,17 @@ void ClipboardPaste(View *view) {
|
||||
EndEdit(buffer, &edits, &view->carets, KILL_SELECTION);
|
||||
}
|
||||
|
||||
void CMD_Paste(HookParam param) {
|
||||
void CMD_Paste() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
ClipboardPaste(active.view);
|
||||
} RegisterCommand(CMD_Paste, "ctrl-v");
|
||||
|
||||
void CMD_Copy(HookParam param) {
|
||||
void CMD_Copy() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
ClipboardCopy(active.view);
|
||||
} RegisterCommand(CMD_Copy, "ctrl-c");
|
||||
|
||||
void CMD_Cut(HookParam param) {
|
||||
void CMD_Cut() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
ClipboardCopy(active.view);
|
||||
|
||||
@@ -284,12 +284,12 @@ void TestParser() {
|
||||
}
|
||||
} RegisterFunction(&TestFunctions, TestParser);
|
||||
|
||||
void CMD_OpenConfig(HookParam param) {
|
||||
void CMD_OpenConfig() {
|
||||
Buffer *buffer = GetBuffer(GlobalConfigBufferID);
|
||||
Open(buffer->name);
|
||||
} RegisterCommand(CMD_OpenConfig, "", "Open the global config file");
|
||||
|
||||
void CMD_OpenConfigOptions(HookParam param) {
|
||||
void CMD_OpenConfigOptions() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
@@ -303,7 +303,7 @@ void CMD_OpenConfigOptions(HookParam param) {
|
||||
default: InvalidCodepath();
|
||||
}
|
||||
}
|
||||
For (GlobalHooks) {
|
||||
For (GlobalCommands) {
|
||||
RawAppendf(main.buffer, "\n:Set %-50S '%S'", it.name, it.binding);
|
||||
}
|
||||
} RegisterCommand(CMD_OpenConfigOptions, "", "List available variables and associated documentation inside the command window");
|
||||
@@ -334,7 +334,7 @@ void EvalCommandsLineByLine(BSet set) {
|
||||
NextActiveWindowID = save_next;
|
||||
}
|
||||
|
||||
void CMD_EvalCommandsLineByLine(HookParam param) {
|
||||
void CMD_EvalCommandsLineByLine() {
|
||||
BSet set = GetBSet(PrimaryWindowID);
|
||||
EvalCommandsLineByLine(set);
|
||||
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
|
||||
|
||||
135
src/text_editor/fuzzy_search_view.cpp
Normal file
135
src/text_editor/fuzzy_search_view.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
String16 FetchFuzzyViewLoadLine(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Range range = view->carets[0].range;
|
||||
String16 string = GetString(buffer, range);
|
||||
if (GetSize(range) == 0) {
|
||||
Int line = PosToLine(buffer, range.min);
|
||||
if (line == 0) {
|
||||
line = ClampTop(1ll, buffer->line_starts.len - 1ll);
|
||||
}
|
||||
string = GetLineStringWithoutNL(buffer, line);
|
||||
|
||||
Int idx = 0;
|
||||
String16 delim = u"||>";
|
||||
if (Seek(string, delim, &idx, SeekFlag_None)) {
|
||||
string = Skip(string, idx + delim.len);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
void OpenCommand(BSet active) {
|
||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||
Open(string);
|
||||
}
|
||||
|
||||
float NewFuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
// try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go
|
||||
return score;
|
||||
}
|
||||
|
||||
float FuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
for (Int outer_pi = 0; outer_pi < p.len; outer_pi += 1) {
|
||||
String16 pit = Skip(p, outer_pi);
|
||||
if (IsWhitespace(At(pit, 0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float matching = 0;
|
||||
for (Int outer_si = 0; outer_si < s.len; outer_si += 1) {
|
||||
String16 sit = Skip(s, outer_si);
|
||||
if (IsWhitespace(At(sit, 0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Int si = 0;
|
||||
Int pi = 0;
|
||||
for (;si < sit.len && pi < pit.len;) {
|
||||
while (si < sit.len && IsWhitespace(sit[si])) si += 1;
|
||||
while (pi < pit.len && IsWhitespace(pit[pi])) pi += 1;
|
||||
if (pi >= pit.len) break;
|
||||
if (si >= sit.len) break;
|
||||
|
||||
if (ToLowerCase(sit[si]) == ToLowerCase(pit[pi])) {
|
||||
matching += 1.0f;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
si += 1;
|
||||
pi += 1;
|
||||
}
|
||||
}
|
||||
score += matching;
|
||||
}
|
||||
score = score / (float)s.len;
|
||||
return score;
|
||||
}
|
||||
|
||||
inline bool MergeSortCompare(FuzzyPair *a, FuzzyPair *b) {
|
||||
bool result = a->rating > b->rating;
|
||||
return result;
|
||||
}
|
||||
|
||||
Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_min, Int line_max, String16 needle) {
|
||||
ProfileFunction();
|
||||
if (line_min < 0 || line_min >= buffer->line_starts.len) return {};
|
||||
if (line_max < 0 || line_min > buffer->line_starts.len) return {};
|
||||
Array<FuzzyPair> ratings = {allocator};
|
||||
Reserve(&ratings, line_max - line_min + 4);
|
||||
for (Int i = line_min; i < line_max; i += 1) {
|
||||
String16 s = GetLineStringWithoutNL(buffer, i);
|
||||
|
||||
Int idx = 0;
|
||||
if (Seek(s, u"||>", &idx, SeekFlag_None)) {
|
||||
s = GetPrefix(s, idx);
|
||||
} else if (Seek(s, u"<||", &idx, SeekFlag_None)) {
|
||||
s = GetPrefix(s, idx);
|
||||
}
|
||||
s = Trim(s);
|
||||
|
||||
float rating = FuzzyRate(s, needle);
|
||||
Add(&ratings, {(int32_t)i, rating});
|
||||
}
|
||||
Array<FuzzyPair> temp = Copy(allocator, ratings);
|
||||
MergeSort(ratings.len, ratings.data, temp.data);
|
||||
return ratings;
|
||||
}
|
||||
|
||||
void UpdateFuzzySearchView() {
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
||||
uint64_t hash = HashBytes(line_string.data, line_string.len * sizeof(char16_t));
|
||||
if (active.view->prev_search_line_hash != hash) {
|
||||
active.view->prev_search_line_hash = hash;
|
||||
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, active.buffer, 1, active.buffer->line_starts.len, line_string);
|
||||
|
||||
Buffer *scratch_buff = CreateScratchBuffer(scratch, active.buffer->cap);
|
||||
RawAppend(scratch_buff, line_string);
|
||||
For(IterateInReverse(&ratings)) {
|
||||
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
|
||||
if (s.len == 0) continue;
|
||||
RawAppend(scratch_buff, u"\n");
|
||||
RawAppend(scratch_buff, s);
|
||||
}
|
||||
|
||||
Caret caret = active.view->carets[0];
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
SelectEntireBuffer(active.view);
|
||||
Replace(active.view, GetString(scratch_buff));
|
||||
active.view->carets[0] = caret;
|
||||
}
|
||||
}
|
||||
|
||||
void SetFuzzy(View *view) {
|
||||
AddCommand(&view->commands, "Open", "ctrl-q | enter | f12", [](){
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
NextActiveWindowID = main.window->id;
|
||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||
Open(string);
|
||||
});
|
||||
view->update_hook = UpdateFuzzySearchView;
|
||||
}
|
||||
@@ -33,18 +33,32 @@ BufferID NullBufferID;
|
||||
ViewID NullViewID;
|
||||
WindowID NullWindowID;
|
||||
|
||||
// hidden floating window
|
||||
WindowID DebugWindowID;
|
||||
ViewID DebugViewID;
|
||||
BufferID DebugBufferID;
|
||||
WindowID CommandWindowID;
|
||||
WindowID StatusBarWindowID;
|
||||
WindowID SearchWindowID;
|
||||
ViewID SearchViewID;
|
||||
BufferID SearchBufferID;
|
||||
WindowID BuildWindowID;
|
||||
ViewID BuildViewID;
|
||||
BufferID BuildBufferID;
|
||||
#ifdef PLUGIN_DEBUG_WINDOW
|
||||
WindowID DebugWindowID;
|
||||
ViewID DebugViewID;
|
||||
BufferID DebugBufferID;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_COMMAND_WINDOW
|
||||
WindowID CommandWindowID;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_SEARCH_WINDOW
|
||||
WindowID SearchWindowID;
|
||||
ViewID SearchViewID;
|
||||
BufferID SearchBufferID;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_STATUS_WINDOW
|
||||
WindowID StatusWindowID;
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_BUILD_WINDOW
|
||||
WindowID BuildWindowID;
|
||||
ViewID BuildViewID;
|
||||
BufferID BuildBufferID;
|
||||
#endif
|
||||
|
||||
BufferID SearchProjectBufferID;
|
||||
BufferID GlobalConfigBufferID;
|
||||
|
||||
@@ -92,7 +106,7 @@ String Intern(InternTable *table, String string) {
|
||||
// optimize worst offenders (like event text)
|
||||
InternTable GlobalInternTable;
|
||||
|
||||
Array<Hook> GlobalHooks;
|
||||
Array<Command> GlobalCommands;
|
||||
Array<FunctionData> TestFunctions;
|
||||
Array<Variable> Variables;
|
||||
|
||||
@@ -175,3 +189,8 @@ RegisterVariable(String, InternetBrowser, "firefox");
|
||||
RegisterVariable(String, OpenCodePatterns, ".c .h .cpp .hpp .cc .cxx .rs .go .zig .py .lua .js .ts .jsx .tsx .java .kt .swift .cs .rb .php .html .css .scss .bat .sh .bash .zsh .sql .asm .s .cmake .make .json .yaml .toml .ini .txt .md .rst .Makefile .Dockerfile .gitignore .bashrc .zshrc");
|
||||
RegisterVariable(String, OpenCodeExcludePatterns, "");
|
||||
RegisterVariable(Int, TrimTrailingWhitespace, 1);
|
||||
|
||||
// BEGIN PLUGIN_REMEDYBG
|
||||
RegisterVariable(String, BinaryUnderDebug, "build/te.exe");
|
||||
RegisterVariable(String, RemedyBGPath, "remedybg.exe");
|
||||
// END PLUGIN_REMEDYBG
|
||||
60
src/text_editor/plugin_build_window.cpp
Normal file
60
src/text_editor/plugin_build_window.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
void InitBuildWindow() {
|
||||
Window *window = CreateWind();
|
||||
BuildWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "build"));
|
||||
buffer->special = true;
|
||||
buffer->no_history = true;
|
||||
BuildBufferID = buffer->id;
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
BuildViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
}
|
||||
|
||||
void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Window *window = GetWindow(BuildWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
rect = ©_rect;
|
||||
}
|
||||
Int barsize = window->font->line_spacing * 10;
|
||||
window->document_rect = window->total_rect = CutBottom(rect, barsize);
|
||||
}
|
||||
|
||||
BSet ExecBuild(String cmd) {
|
||||
BSet build = GetBSet(BuildWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
SelectRange(build.view, Range{});
|
||||
ResetBuffer(build.buffer);
|
||||
Exec(build.view->id, true, cmd, WorkDir);
|
||||
main.window->active_goto_list = build.view->id;
|
||||
main.window->goto_list_pos = 0;
|
||||
return build;
|
||||
}
|
||||
|
||||
void CMD_Build() {
|
||||
CMD_SaveAll();
|
||||
#if OS_WINDOWS
|
||||
ExecBuild("build.bat");
|
||||
#else
|
||||
ExecBuild("sh build.sh");
|
||||
#endif
|
||||
BSet main = GetBSet(BuildWindowID);
|
||||
main.window->visible = true;
|
||||
} RegisterCommand(CMD_Build, "f1", "Run build.sh or build.bat in working directory, output is printed in a popup console and a special build buffer");
|
||||
|
||||
void CMD_ShowBuildWindow() {
|
||||
BSet main = GetBSet(BuildWindowID);
|
||||
if (ActiveWindowID != BuildWindowID) {
|
||||
main.window->visible = true;
|
||||
NextActiveWindowID = BuildWindowID;
|
||||
} else {
|
||||
main.window->visible = false;
|
||||
}
|
||||
} RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave");
|
||||
3
src/text_editor/plugin_build_window.h
Normal file
3
src/text_editor/plugin_build_window.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#define PLUGIN_BUILD_WINDOW
|
||||
void InitBuildWindow();
|
||||
void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy);
|
||||
98
src/text_editor/plugin_command_window.cpp
Normal file
98
src/text_editor/plugin_command_window.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
void CMD_ShowCommands() {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowCommands) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (GlobalCommands) {
|
||||
if (it.name == "OpenCommand") {
|
||||
continue;
|
||||
}
|
||||
// RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding);
|
||||
RawAppendf(command_bar.buffer, "\n:%-30S <|| ", it.name);
|
||||
if (it.docs.len) {
|
||||
RawAppendf(command_bar.buffer, "%S", it.docs);
|
||||
}
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window");
|
||||
|
||||
void CMD_ShowDebugBufferList() {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (Buffers) {
|
||||
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
|
||||
if (!is_special) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "ctrl-shift-alt-p", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
|
||||
void CMD_ShowBufferList() {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowBufferList) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (Buffers) {
|
||||
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
|
||||
if (is_special) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowBufferList, "ctrl-p", "List open buffers inside the command window that you can fuzzy search over");
|
||||
|
||||
void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Window *window = GetWindow(CommandWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
rect = ©_rect;
|
||||
}
|
||||
Int barsize = Clamp((Int)window->font->line_spacing*10, (Int)0, (Int)wx - 100);
|
||||
window->document_rect = window->total_rect = CutBottom(rect, barsize);
|
||||
}
|
||||
|
||||
void InitCommandWindow() {
|
||||
Window *window = CreateWind();
|
||||
CommandWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar"));
|
||||
buffer->special = true;
|
||||
buffer->no_history = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
SetFuzzy(view);
|
||||
window->active_view = view->id;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->sync_visibility_with_focus = true;
|
||||
window->lose_focus_on_escape = true;
|
||||
window->jump_history = false;
|
||||
}
|
||||
3
src/text_editor/plugin_command_window.h
Normal file
3
src/text_editor/plugin_command_window.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#define PLUGIN_COMMAND_WINDOW
|
||||
void InitCommandWindow();
|
||||
void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy);
|
||||
@@ -1,15 +1,37 @@
|
||||
void LayoutDebugWindow(HookParam param) {
|
||||
auto p = param.layout;
|
||||
Rect2 screen_rect = Rect0Size((float)p.wx, (float)p.wy);
|
||||
void InitDebugWindow() {
|
||||
Window *window = CreateWind();
|
||||
DebugWindowID = window->id;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
DebugBufferID = buffer->id;
|
||||
buffer->no_history = true;
|
||||
buffer->special = true;
|
||||
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
DebugViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
window->visible = false;
|
||||
}
|
||||
|
||||
void LayoutDebugWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Window *window = GetWindow(DebugWindowID);
|
||||
Rect2 screen_rect = Rect0Size((float)wx, (float)wy);
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
|
||||
Rect2 a = CutRight(&screen_rect, 0.3f * size.x);
|
||||
Rect2 b = CutTop(&a, 0.4f * size.y);
|
||||
Rect2 c = Shrink(b, 20);
|
||||
p.window->document_rect = p.window->total_rect = ToRect2I(c);
|
||||
window->document_rect = window->total_rect = ToRect2I(c);
|
||||
}
|
||||
|
||||
void UpdateDebugWindow(HookParam param) {
|
||||
void UpdateDebugWindow() {
|
||||
ProfileFunction();
|
||||
BSet set = GetBSet(DebugWindowID);
|
||||
if (!set.window->visible) {
|
||||
@@ -55,33 +77,9 @@ void UpdateDebugWindow(HookParam param) {
|
||||
RawAppendf(set.buffer, "int dirty = %d\n", main.buffer->dirty);
|
||||
RawAppendf(set.buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk);
|
||||
RawAppendf(set.buffer, "int temp = %d\n", main.buffer->temp);
|
||||
} RegisterHook(UpdateDebugWindow, HookKind_AppUpdate, "", "Update the debug window");
|
||||
}
|
||||
|
||||
void InitDebugWindow(HookParam param) {
|
||||
Window *window = CreateWind();
|
||||
DebugWindowID = window->id;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
DebugBufferID = buffer->id;
|
||||
buffer->no_history = true;
|
||||
buffer->special = true;
|
||||
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
DebugViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
window->visible = false;
|
||||
|
||||
AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo: LayoutDebugWindow", "", LayoutDebugWindow);
|
||||
} RegisterHook(InitDebugWindow, HookKind_AppInit, "", "Init the debug window");
|
||||
|
||||
void CMD_ToggleDebug(HookParam param) {
|
||||
void CMD_ToggleDebug() {
|
||||
Window *window = GetWindow(DebugWindowID);
|
||||
window->visible = !window->visible;
|
||||
} RegisterCommand(CMD_ToggleDebug, "ctrl-0", "Open a floating window that might become useful for debugging");
|
||||
4
src/text_editor/plugin_debug_window.h
Normal file
4
src/text_editor/plugin_debug_window.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#define PLUGIN_DEBUG_WINDOW
|
||||
void InitDebugWindow();
|
||||
void LayoutDebugWindow(Rect2I *rect, int16_t wx, int16_t wy);
|
||||
void UpdateDebugWindow();
|
||||
@@ -1,8 +1,3 @@
|
||||
RegisterVariable(String, BinaryUnderDebug, "build/te.exe");
|
||||
RegisterVariable(String, RemedyBGPath, "remedybg.exe");
|
||||
|
||||
#if OS_WINDOWS
|
||||
|
||||
#define RDBG_MAX_SERVERNAME_LEN 64
|
||||
|
||||
typedef uint8_t rdbg_Bool;
|
||||
@@ -2101,7 +2096,6 @@ uint8_t command_buf[COMMAND_BUF_SIZE];
|
||||
uint8_t reply_buf[REPLY_BUF_SIZE];
|
||||
ClientContext RDBG_Ctx;
|
||||
|
||||
|
||||
bool RDBG_InitConnection() {
|
||||
enum rdbg_CommandResult res;
|
||||
if (RDBG_Ctx.command_pipe_handle != NULL) {
|
||||
@@ -2162,7 +2156,7 @@ bool RDBG_InitConnection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMD_StartDebugging(HookParam param) {
|
||||
void CMD_StartDebugging() {
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
@@ -2200,7 +2194,7 @@ void CMD_StartDebugging(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_StartDebugging, "f5", "Start debugging, if debugger not active it starts it, uses BinaryUnderDebug");
|
||||
|
||||
void CMD_RunToLineInDebugger(HookParam param) {
|
||||
void CMD_RunToLineInDebugger() {
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
@@ -2217,7 +2211,7 @@ void CMD_RunToLineInDebugger(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_RunToLineInDebugger, "ctrl-f10", "Instruct debugger to execute until line and column under caret");
|
||||
|
||||
void CMD_StopDebugging(HookParam param) {
|
||||
void CMD_StopDebugging() {
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
@@ -2232,7 +2226,7 @@ void CMD_StopDebugging(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_StopDebugging, "shift-f5", "Stop debugging");
|
||||
|
||||
void CMD_AddBreakpoint(HookParam param) {
|
||||
void CMD_AddBreakpoint() {
|
||||
if (!RDBG_InitConnection()) {
|
||||
return;
|
||||
}
|
||||
@@ -2249,7 +2243,7 @@ void CMD_AddBreakpoint(HookParam param) {
|
||||
}
|
||||
} RegisterCommand(CMD_AddBreakpoint, "f9", "Add a breakpoint at filename + line");
|
||||
|
||||
void HOOK_QuitDebugger(HookParam param) {
|
||||
void QuitDebugger() {
|
||||
if (RDBG_Ctx.command_pipe_handle == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -2257,7 +2251,4 @@ void HOOK_QuitDebugger(HookParam param) {
|
||||
enum rdbg_CommandResult res;
|
||||
ExitDebugger(&RDBG_Ctx, &res);
|
||||
CloseConnection(&RDBG_Ctx);
|
||||
} RegisterHook(HOOK_QuitDebugger, HookKind_AppQuit, "", "exit the connected debugger");
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
2
src/text_editor/plugin_remedybg.h
Normal file
2
src/text_editor/plugin_remedybg.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define PLUGIN_REMEDYBG
|
||||
void QuitDebugger();
|
||||
@@ -1,4 +1,4 @@
|
||||
void CMD_Search(HookParam param) {
|
||||
void CMD_Search() {
|
||||
BSet main = GetBSet(ActiveWindowID);
|
||||
String16 string = {};
|
||||
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
|
||||
@@ -23,23 +23,23 @@ void SearchWindowFindNext(bool forward = true) {
|
||||
CenterView(PrimaryWindowID);
|
||||
}
|
||||
|
||||
void CMD_SearchNextInSearch(HookParam param) {
|
||||
void CMD_SearchNextInSearch() {
|
||||
SearchWindowFindNext(true);
|
||||
}
|
||||
|
||||
void CMD_SearchPrevInSearch(HookParam param) {
|
||||
void CMD_SearchPrevInSearch() {
|
||||
SearchWindowFindNext(false);
|
||||
}
|
||||
|
||||
void CMD_SearchNext(HookParam param) {
|
||||
void CMD_SearchNext() {
|
||||
SearchWindowFindNext(true);
|
||||
} RegisterCommand(CMD_SearchNext, "f3", "Go to the next occurence of the search window needle");
|
||||
|
||||
void CMD_SearchPrev(HookParam param) {
|
||||
void CMD_SearchPrev() {
|
||||
SearchWindowFindNext(false);
|
||||
} RegisterCommand(CMD_SearchPrev, "shift-f3", "Go to the previous occurence of the search window needle");
|
||||
|
||||
void CMD_SearchAll(HookParam param) {
|
||||
void CMD_SearchAll() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet set = GetBSet(SearchWindowID);
|
||||
String16 needle = GetString(set.buffer, GetRange(set.buffer));
|
||||
@@ -47,38 +47,15 @@ void CMD_SearchAll(HookParam param) {
|
||||
set.window->visible = false;
|
||||
} RegisterCommand(CMD_SearchAll, "alt-f3", "Use the search window needle and seek all the possible occurences in current buffer");
|
||||
|
||||
void CMD_ToggleCaseSensitiveSearch(HookParam param) {
|
||||
void CMD_ToggleCaseSensitiveSearch() {
|
||||
SearchCaseSensitive = !SearchCaseSensitive;
|
||||
} RegisterCommand(CMD_ToggleCaseSensitiveSearch, "alt-c", "Text editor wide search toggle, should apply to most search things");
|
||||
|
||||
void CMD_ToggleSearchWordBoundary(HookParam param) {
|
||||
void CMD_ToggleSearchWordBoundary() {
|
||||
SearchWordBoundary = !SearchWordBoundary;
|
||||
} RegisterCommand(CMD_ToggleSearchWordBoundary, "alt-w", "Text editor wide search toggle, should apply to most search things");
|
||||
|
||||
void UpdateSearchWindow(HookParam param) {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
if (active.window->id == SearchWindowID && active.buffer->begin_frame_change_id != active.buffer->change_id) {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet set = GetBSet(SearchWindowID);
|
||||
main.view->carets[0] = main.window->search_bar_anchor;
|
||||
String16 seek = GetString(set.buffer, GetRange(set.buffer));
|
||||
Find(main.view, seek, true);
|
||||
CenterView(main.window->id);
|
||||
}
|
||||
} RegisterHook(UpdateSearchWindow, HookKind_AppUpdate, "", "Update the search window");
|
||||
|
||||
void LayoutSearchWindow(HookParam param) {
|
||||
auto p = param.layout;
|
||||
Rect2I copy_rect = *p.rect;
|
||||
if (!p.window->visible) {
|
||||
p.rect = ©_rect;
|
||||
}
|
||||
Int barsize = GetExpandingBarSize(p.window);
|
||||
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
||||
p.window->line_numbers_rect = CutLeft(&p.window->document_rect, p.window->font->char_spacing * 6);
|
||||
}
|
||||
|
||||
void InitSearchWindow(HookParam param) {
|
||||
void InitSearchWindow() {
|
||||
Window *window = CreateWind();
|
||||
SearchWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "search"));
|
||||
@@ -96,8 +73,31 @@ void InitSearchWindow(HookParam param) {
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
AddCommand(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll);
|
||||
AddCommand(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
|
||||
AddCommand(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
|
||||
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutSearchWindow", "", LayoutSearchWindow);
|
||||
} RegisterHook(InitSearchWindow, HookKind_AppInit, "", "Init the search window");
|
||||
AddCommand(&view->commands, "SearchAll", "alt-enter", CMD_SearchAll);
|
||||
AddCommand(&view->commands, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
|
||||
AddCommand(&view->commands, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
|
||||
}
|
||||
|
||||
void LayoutSearchWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Window *window = GetWindow(SearchWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
rect = ©_rect;
|
||||
}
|
||||
Int barsize = GetExpandingBarSize(window);
|
||||
window->document_rect = window->total_rect = CutBottom(rect, barsize);
|
||||
window->line_numbers_rect = CutLeft(&window->document_rect, window->font->char_spacing * 6);
|
||||
}
|
||||
|
||||
void UpdateSearchWindow() {
|
||||
if (ActiveWindowID == SearchWindowID) {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
if (active.buffer->begin_frame_change_id != active.buffer->change_id) {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main.view->carets[0] = main.window->search_bar_anchor;
|
||||
String16 seek = GetString(active.buffer, GetRange(active.buffer));
|
||||
Find(main.view, seek, true);
|
||||
CenterView(main.window->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
4
src/text_editor/plugin_search_window.h
Normal file
4
src/text_editor/plugin_search_window.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#define PLUGIN_SEARCH_WINDOW
|
||||
void InitSearchWindow();
|
||||
void LayoutSearchWindow(Rect2I *rect, int16_t wx, int16_t wy);
|
||||
void UpdateSearchWindow();
|
||||
@@ -1,6 +1,33 @@
|
||||
void StatusWindowUpdate(HookParam param) {
|
||||
void InitStatusWindow() {
|
||||
Window *window = CreateWind();
|
||||
StatusWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "status_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_line_highlight = true;
|
||||
window->secondary_window_style = true;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
window->lose_focus_on_escape = true;
|
||||
}
|
||||
|
||||
void LayoutStatusWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Window *window = GetWindow(StatusWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
rect = ©_rect;
|
||||
}
|
||||
Int barsize = GetExpandingBarSize(window);
|
||||
window->document_rect = window->total_rect = CutBottom(rect, barsize);
|
||||
}
|
||||
|
||||
void UpdateStatusWindow() {
|
||||
ProfileFunction();
|
||||
Window *status_bar_window = GetWindow(StatusBarWindowID, NULL);
|
||||
Window *status_bar_window = GetWindow(StatusWindowID, NULL);
|
||||
Scratch scratch;
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet title = GetBSet(status_bar_window);
|
||||
@@ -67,33 +94,4 @@ void StatusWindowUpdate(HookParam param) {
|
||||
|
||||
SelectRange(title.view, MakeRange(0));
|
||||
ResetHistory(title.buffer);
|
||||
} RegisterHook(StatusWindowUpdate, HookKind_AppUpdate, "", "");
|
||||
|
||||
void LayoutStatusWindow(HookParam param) {
|
||||
auto p = param.layout;
|
||||
Rect2I copy_rect = *p.rect;
|
||||
if (!p.window->visible) {
|
||||
p.rect = ©_rect;
|
||||
}
|
||||
Int barsize = GetExpandingBarSize(p.window);
|
||||
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
||||
} RegisterHook(LayoutStatusWindow, HookKind_HandleWindowLayout, "", "Layout the status window");
|
||||
|
||||
void StatusWindowInit(HookParam param) {
|
||||
Window *window = CreateWind();
|
||||
StatusBarWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "status_bar"));
|
||||
buffer->special = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
window->active_view = view->id;
|
||||
// window->font = &SecondaryFont;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->draw_line_highlight = true;
|
||||
window->secondary_window_style = true;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
window->lose_focus_on_escape = true;
|
||||
AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo LayoutStatusWindow", "", LayoutStatusWindow);
|
||||
} RegisterHook(StatusWindowInit, HookKind_AppInit, "", "Init the status window");
|
||||
}
|
||||
4
src/text_editor/plugin_status_window.h
Normal file
4
src/text_editor/plugin_status_window.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#define PLUGIN_STATUS_WINDOW
|
||||
void InitStatusWindow();
|
||||
void LayoutStatusWindow(Rect2I *rect, int16_t wx, int16_t wy);
|
||||
void UpdateStatusWindow();
|
||||
@@ -4,7 +4,7 @@
|
||||
// the appropriate handles. This happens in this case when git grep calls
|
||||
// 'less' program which errors out and doesn't print anything
|
||||
// @todo: maybe I should ask someone smarter about this!
|
||||
void UpdateProcesses(HookParam param) {
|
||||
void UpdateProcesses() {
|
||||
IterRemove(ActiveProcesses) {
|
||||
IterRemovePrepare(ActiveProcesses);
|
||||
Scratch scratch;
|
||||
@@ -19,14 +19,16 @@ void UpdateProcesses(HookParam param) {
|
||||
remove_item = true;
|
||||
}
|
||||
}
|
||||
} RegisterHook(UpdateProcesses, HookKind_AppUpdate, "", "Polls all the processes and outputs the results to corresponding views");
|
||||
}
|
||||
|
||||
void Exec(ViewID view, bool scroll_to_end, String cmd, String working_dir) {
|
||||
Process process = SpawnProcess(cmd, working_dir, {}, ProcessEnviroment);
|
||||
ReportDebugf("process %lld start. is_valid = %d cmd = %S working_dir = %S", process.id, process.is_valid, cmd, working_dir);
|
||||
process.view_id = view.id;
|
||||
process.scroll_to_end = scroll_to_end;
|
||||
if (process.is_valid) Add(&ActiveProcesses, process);
|
||||
if (process.is_valid) {
|
||||
Add(&ActiveProcesses, process);
|
||||
}
|
||||
}
|
||||
|
||||
void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) {
|
||||
|
||||
@@ -15,26 +15,37 @@
|
||||
#include "render/font.cpp"
|
||||
#include "render/opengl.cpp"
|
||||
#include "text_editor.h"
|
||||
#include "plugin_command_window.h"
|
||||
#include "plugin_search_window.h"
|
||||
#include "plugin_debug_window.h"
|
||||
#include "plugin_status_window.h"
|
||||
#include "plugin_build_window.h"
|
||||
#if OS_WINDOWS
|
||||
#include "plugin_remedybg.h"
|
||||
#endif
|
||||
#include "globals.cpp"
|
||||
#include "coroutines.cpp"
|
||||
#include "buffer.cpp"
|
||||
#include "view.cpp"
|
||||
#include "window.cpp"
|
||||
#include "window_status.cpp"
|
||||
#include "window_command.cpp"
|
||||
#include "window_debug.cpp"
|
||||
#include "window_search.cpp"
|
||||
#include "window_build.cpp"
|
||||
#include "fuzzy_search_view.cpp"
|
||||
#include "process.cpp"
|
||||
#include "event.cpp"
|
||||
#include "config.cpp"
|
||||
#include "commands.cpp"
|
||||
#include "commands_clipboard.cpp"
|
||||
#include "scratch.cpp"
|
||||
#include "draw.cpp"
|
||||
#include "test/tests.cpp"
|
||||
|
||||
#include "remedybg_plugin.cpp"
|
||||
#include "commands_clipboard.cpp"
|
||||
#include "plugin_command_window.cpp"
|
||||
#include "plugin_search_window.cpp"
|
||||
#include "plugin_status_window.cpp"
|
||||
#include "plugin_build_window.cpp"
|
||||
#include "plugin_debug_window.cpp"
|
||||
#if OS_WINDOWS
|
||||
#include "plugin_remedybg.cpp"
|
||||
#endif
|
||||
|
||||
#if OS_WASM
|
||||
EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), {
|
||||
@@ -399,20 +410,20 @@ void OnCommand(Event event) {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
|
||||
bool executed = false;
|
||||
For (active.view->hooks) {
|
||||
For (active.view->commands) {
|
||||
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
it.function();
|
||||
executed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (executed == false) {
|
||||
For (GlobalHooks) {
|
||||
For (GlobalCommands) {
|
||||
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function(HookParam{});
|
||||
it.function();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -427,7 +438,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (event.kind == EVENT_QUIT) {
|
||||
CMD_Quit({});
|
||||
CMD_Quit();
|
||||
}
|
||||
|
||||
IF_DEBUG(AssertRanges(main.view->carets));
|
||||
@@ -436,17 +447,17 @@ void OnCommand(Event event) {
|
||||
|
||||
void EvalCommand(String command) {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
For (active.view->hooks) {
|
||||
For (active.view->commands) {
|
||||
if (it.name == command) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
it.function();
|
||||
return;
|
||||
}
|
||||
}
|
||||
For (GlobalHooks) {
|
||||
For (GlobalCommands) {
|
||||
if (it.name == command) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
it.function();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -508,7 +519,7 @@ void GarbageCollect() {
|
||||
|
||||
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer ? buffer->name : String{"NULL"});
|
||||
remove_item = true;
|
||||
Dealloc(&it->hooks);
|
||||
Dealloc(&it->commands);
|
||||
Dealloc(it);
|
||||
}
|
||||
|
||||
@@ -545,7 +556,7 @@ void GarbageCollect() {
|
||||
RawAppendf(GCInfoBuffer, "Wind %d %d %d %d %d\n", (int)it->id.id, (int)it->total_rect.min.x, (int)it->total_rect.min.y, (int)it->total_rect.max.x, (int)it->total_rect.max.y);
|
||||
Dealloc(&it->goto_history);
|
||||
Dealloc(&it->goto_redo);
|
||||
Dealloc(&it->hooks);
|
||||
Dealloc(&it->commands);
|
||||
Dealloc(sys_allocator, it);
|
||||
remove_item = true;
|
||||
} else {
|
||||
@@ -581,25 +592,30 @@ void Update(Event event) {
|
||||
|
||||
OnCommand(event);
|
||||
|
||||
#ifdef PLUGIN_DEBUG_WINDOW
|
||||
UpdateDebugWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_STATUS_WINDOW
|
||||
UpdateStatusWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_SEARCH_WINDOW
|
||||
UpdateSearchWindow();
|
||||
#endif
|
||||
|
||||
// ActiveViewHook
|
||||
{
|
||||
BSet set = GetBSet(ActiveWindowID);
|
||||
For (set.view->hooks) {
|
||||
if (it.kind == HookKind_AppUpdate) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function(HookParam{});
|
||||
}
|
||||
}
|
||||
|
||||
For (GlobalHooks) {
|
||||
if (it.kind == HookKind_AppUpdate) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function(HookParam{});
|
||||
}
|
||||
if (set.view->update_hook) {
|
||||
set.view->update_hook();
|
||||
}
|
||||
}
|
||||
|
||||
UpdateProcesses();
|
||||
CoUpdate(&event);
|
||||
|
||||
|
||||
For(IterateInReverse(&order)) {
|
||||
if (!it->visible) continue;
|
||||
View *view = GetView(it->active_view);
|
||||
@@ -664,8 +680,19 @@ void Update(Event event) {
|
||||
|
||||
// Behavior where these windows cannot be visible at the same time
|
||||
{
|
||||
WindowID id[] = {BuildWindowID, CommandWindowID, SearchWindowID};
|
||||
for (int i = 0; i < Lengthof(id); i += 1) {
|
||||
WindowID id[] = {
|
||||
{-1}, // This is just so that we have a valid array if all windows are disabled
|
||||
#ifdef PLUGIN_BUILD_WINDOW
|
||||
BuildWindowID,
|
||||
#endif
|
||||
#ifdef PLUGIN_COMMAND_WINDOW
|
||||
CommandWindowID,
|
||||
#endif
|
||||
#ifdef PLUGIN_SEARCH_WINDOW
|
||||
SearchWindowID,
|
||||
#endif
|
||||
};
|
||||
for (int i = 1; i < Lengthof(id); i += 1) {
|
||||
if (ActiveWindowID == id[i]) {
|
||||
for (int j = 0; j < Lengthof(id); j += 1) {
|
||||
if (i == j) continue;
|
||||
@@ -812,6 +839,12 @@ int main(int argc, char **argv)
|
||||
WorkDir = GetWorkingDir(Perm);
|
||||
{
|
||||
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
|
||||
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
|
||||
sdl_config_path = Chop(sdl_config_path, 1); // chop '/'
|
||||
}
|
||||
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '/') {
|
||||
sdl_config_path = Chop(sdl_config_path, 1); // chop '/'
|
||||
}
|
||||
ConfigDir = NormalizePath(Perm, sdl_config_path);
|
||||
SDL_free(sdl_config_path.data);
|
||||
}
|
||||
@@ -889,7 +922,7 @@ int main(int argc, char **argv)
|
||||
CreateWind();
|
||||
InitOS(ReportWarningf);
|
||||
|
||||
For (GlobalHooks) {
|
||||
For (GlobalCommands) {
|
||||
if (it.binding.len != 0) {
|
||||
it.trigger = ParseKeyCached(it.binding);
|
||||
}
|
||||
@@ -915,14 +948,25 @@ int main(int argc, char **argv)
|
||||
CoResume(co_data);
|
||||
#endif
|
||||
|
||||
{
|
||||
For (GlobalHooks) {
|
||||
if (it.kind == HookKind_AppInit) {
|
||||
ProfileScopeEx(it.name);
|
||||
it.function({});
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef PLUGIN_STATUS_WINDOW
|
||||
InitStatusWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_COMMAND_WINDOW
|
||||
InitCommandWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_DEBUG_WINDOW
|
||||
InitDebugWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_BUILD_WINDOW
|
||||
InitBuildWindow();
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_SEARCH_WINDOW
|
||||
InitSearchWindow();
|
||||
#endif
|
||||
|
||||
#if OS_WASM
|
||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||
|
||||
@@ -25,62 +25,11 @@ struct HistoryEntry {
|
||||
double time;
|
||||
};
|
||||
|
||||
enum HookKind {
|
||||
HookKind_Invalid,
|
||||
|
||||
HookKind_AppInit,
|
||||
HookKind_AppUpdate,
|
||||
HookKind_AppQuit,
|
||||
|
||||
// Should we have commands like PostCommand, PreCommand? what would be the purpose?
|
||||
HookKind_Command,
|
||||
|
||||
// Currently we are only basically allowing control over non-layouted windows.
|
||||
// How can this be expanded?
|
||||
// - Changing the layout algorithm: this seems like a decent one
|
||||
// - What beside that?
|
||||
HookKind_HandleWindowLayout,
|
||||
|
||||
// Move the special window rendering to hooks?
|
||||
// HookKind_RenderWindow,
|
||||
// HookKind_CreateWindow,
|
||||
|
||||
// How to handle formatters for multiple languages and other saving rules???
|
||||
HookKind_BeforeSavingBuffer,
|
||||
HookKind_CreateBuffer,
|
||||
// HookKind_BufferSave,
|
||||
// HookKind_AfterBufferSave,
|
||||
|
||||
// HookKind_ResolveOpen,
|
||||
|
||||
// HookKind_BeforeBufferOpen,
|
||||
// HookKind_BufferOpen,
|
||||
// HookKind_AfterBufferOpen,
|
||||
|
||||
HookKind_CreateView,
|
||||
|
||||
};
|
||||
|
||||
// Global hooks, per (window, view, buffer) hooks
|
||||
|
||||
struct HookParam {
|
||||
union {
|
||||
Buffer *buffer;
|
||||
struct {
|
||||
Window *window;
|
||||
Rect2I *rect;
|
||||
int16_t wx;
|
||||
int16_t wy;
|
||||
} layout;
|
||||
};
|
||||
};
|
||||
|
||||
typedef void HookFunction(HookParam param);
|
||||
struct Hook {
|
||||
HookKind kind;
|
||||
typedef void CMDFunction();
|
||||
struct Command {
|
||||
String name;
|
||||
String docs;
|
||||
HookFunction *function;
|
||||
CMDFunction *function;
|
||||
String binding;
|
||||
struct Trigger *trigger;
|
||||
};
|
||||
@@ -104,17 +53,17 @@ struct Buffer {
|
||||
Array<HistoryEntry> undo_stack;
|
||||
Array<HistoryEntry> redo_stack;
|
||||
int edit_phase;
|
||||
Array<Hook> hooks;
|
||||
Array<Command> commands;
|
||||
struct {
|
||||
unsigned no_history : 1;
|
||||
unsigned no_line_starts : 1;
|
||||
unsigned dirty : 1;
|
||||
unsigned changed_on_disk : 1;
|
||||
unsigned temp : 1;
|
||||
unsigned dont_try_to_save_in_bulk_ops : 1;
|
||||
unsigned close : 1;
|
||||
unsigned special : 1;
|
||||
unsigned is_dir : 1;
|
||||
uint32_t no_history : 1;
|
||||
uint32_t no_line_starts : 1;
|
||||
uint32_t dirty : 1;
|
||||
uint32_t changed_on_disk : 1;
|
||||
uint32_t temp : 1;
|
||||
uint32_t dont_try_to_save_in_bulk_ops : 1;
|
||||
uint32_t close : 1;
|
||||
uint32_t special : 1;
|
||||
uint32_t is_dir : 1;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -129,11 +78,12 @@ struct View {
|
||||
bool update_scroll;
|
||||
|
||||
String hook_cmd;
|
||||
Array<Hook> hooks;
|
||||
Array<Command> commands;
|
||||
Function *update_hook;
|
||||
uint64_t prev_search_line_hash;
|
||||
struct {
|
||||
unsigned close : 1;
|
||||
unsigned special : 1;
|
||||
uint32_t close : 1;
|
||||
uint32_t special : 1;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -166,7 +116,7 @@ struct Window {
|
||||
ViewID active_goto_list;
|
||||
Int goto_list_pos;
|
||||
|
||||
Array<Hook> hooks;
|
||||
Array<Command> commands;
|
||||
struct {
|
||||
uint32_t draw_scrollbar : 1;
|
||||
uint32_t draw_line_numbers : 1;
|
||||
@@ -310,24 +260,21 @@ struct ResolvedOpen {
|
||||
bool existing_buffer;
|
||||
};
|
||||
|
||||
void AddHook(Array<Hook> *arr, HookKind kind, String name, String binding, HookFunction *function);
|
||||
void AddCommand(Array<Hook> *arr, String name, String binding, HookFunction *function);
|
||||
#define RegisterCommand(name, ...) Register_Command RC__##name(&GlobalHooks, HookKind_Command, name, #name, __VA_ARGS__)
|
||||
#define RegisterHook(name, kind, bindings, docs) Register_Command RC__##name(&GlobalHooks, kind, name, #name, bindings, docs)
|
||||
void AddCommand(Array<Command> *arr, String name, String binding, CMDFunction *function);
|
||||
#define RegisterCommand(name, ...) Register_Command RC__##name(&GlobalCommands, name, #name, __VA_ARGS__)
|
||||
struct Register_Command {
|
||||
Register_Command(Array<Hook> *funcs, HookKind kind, HookFunction *function, String name, String binding, String docs = "") {
|
||||
Register_Command(Array<Command> *funcs, CMDFunction *function, String name, String binding, String docs = "") {
|
||||
int64_t pos = 0;
|
||||
if (Seek(name, "_", &pos, 0)) {
|
||||
name = Skip(name, pos + 1);
|
||||
}
|
||||
Hook hook = {};
|
||||
hook.kind = kind;
|
||||
hook.name = name;
|
||||
hook.binding = binding;
|
||||
hook.function = function;
|
||||
hook.docs = docs;
|
||||
Command cmd = {};
|
||||
cmd.name = name;
|
||||
cmd.binding = binding;
|
||||
cmd.function = function;
|
||||
cmd.docs = docs;
|
||||
Reserve(funcs, 512);
|
||||
Add(funcs, hook);
|
||||
Add(funcs, cmd);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ API View *CreateView(BufferID active_buffer) {
|
||||
view->id = AllocViewID(view);
|
||||
view->active_buffer = active_buffer;
|
||||
view->carets.allocator = al;
|
||||
view->hooks.allocator = al;
|
||||
view->commands.allocator = al;
|
||||
Add(&view->carets, {0, 0});
|
||||
Add(&Views, view);
|
||||
return view;
|
||||
@@ -16,7 +16,7 @@ API View *CreateView(BufferID active_buffer) {
|
||||
|
||||
void Dealloc(View *view) {
|
||||
Dealloc(&view->carets);
|
||||
Dealloc(&view->hooks);
|
||||
Dealloc(&view->commands);
|
||||
Dealloc(view->carets.allocator, view);
|
||||
}
|
||||
|
||||
@@ -115,26 +115,6 @@ String16 FetchLoadWord(View *view) {
|
||||
return string;
|
||||
}
|
||||
|
||||
String16 FetchFuzzyViewLoadLine(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Range range = view->carets[0].range;
|
||||
String16 string = GetString(buffer, range);
|
||||
if (GetSize(range) == 0) {
|
||||
Int line = PosToLine(buffer, range.min);
|
||||
if (line == 0) {
|
||||
line = ClampTop(1ll, buffer->line_starts.len - 1ll);
|
||||
}
|
||||
string = GetLineStringWithoutNL(buffer, line);
|
||||
|
||||
Int idx = 0;
|
||||
String16 delim = u"||>";
|
||||
if (Seek(string, delim, &idx, SeekFlag_None)) {
|
||||
string = Skip(string, idx + delim.len);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
char16_t GetIndentChar() {
|
||||
char16_t c = u' ';
|
||||
if (IndentKindWhichIsTabsOrSpaces == "spaces") {
|
||||
|
||||
@@ -138,19 +138,25 @@ void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
ProfileFunction();
|
||||
Rect2I screen_rect = RectI0Size(wx, wy);
|
||||
|
||||
ForItem (n, Windows) {
|
||||
ForItem (hook, n->hooks) {
|
||||
if (hook.kind == HookKind_HandleWindowLayout) {
|
||||
ProfileScopeEx(it.name);
|
||||
HookParam param = {};
|
||||
param.layout.window = n;
|
||||
param.layout.rect = &screen_rect;
|
||||
param.layout.wx = wx;
|
||||
param.layout.wy = wy;
|
||||
hook.function(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef PLUGIN_STATUS_WINDOW
|
||||
LayoutStatusWindow(&screen_rect, wx, wy);
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_SEARCH_WINDOW
|
||||
LayoutSearchWindow(&screen_rect, wx, wy);
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_COMMAND_WINDOW
|
||||
LayoutCommandWindow(&screen_rect, wx, wy);
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_DEBUG_WINDOW
|
||||
LayoutDebugWindow(&screen_rect, wx, wy);
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_BUILD_WINDOW
|
||||
LayoutBuildWindow(&screen_rect, wx, wy);
|
||||
#endif
|
||||
|
||||
// Column layout
|
||||
Int c = 0;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
void LayoutBuildWindow(HookParam param) {
|
||||
auto p = param.layout;
|
||||
Rect2I copy_rect = *p.rect;
|
||||
if (!p.window->visible) {
|
||||
p.rect = ©_rect;
|
||||
}
|
||||
Int barsize = p.window->font->line_spacing * 10;
|
||||
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
||||
}
|
||||
|
||||
void CMD_ShowBuildWindow(HookParam param) {
|
||||
BSet main = GetBSet(BuildWindowID);
|
||||
if (ActiveWindowID != BuildWindowID) {
|
||||
main.window->visible = true;
|
||||
NextActiveWindowID = BuildWindowID;
|
||||
} else {
|
||||
main.window->visible = false;
|
||||
}
|
||||
} RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave");
|
||||
|
||||
void InitBuildWindow(HookParam param) {
|
||||
Window *window = CreateWind();
|
||||
BuildWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "build"));
|
||||
buffer->special = true;
|
||||
buffer->no_history = true;
|
||||
BuildBufferID = buffer->id;
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
BuildViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutBuildWindow", "", LayoutBuildWindow);
|
||||
} RegisterHook(InitBuildWindow, HookKind_AppInit, "", "Init the build window");
|
||||
@@ -1,252 +0,0 @@
|
||||
void CMD_ShowCommands(HookParam param) {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowCommands) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (GlobalHooks) {
|
||||
if (it.name == "OpenCommand") {
|
||||
continue;
|
||||
}
|
||||
// RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding);
|
||||
RawAppendf(command_bar.buffer, "\n:%-30S <|| ", it.name);
|
||||
if (it.docs.len) {
|
||||
RawAppendf(command_bar.buffer, "%S", it.docs);
|
||||
}
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window");
|
||||
|
||||
void CMD_ShowDebugBufferList(HookParam param) {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (Buffers) {
|
||||
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
|
||||
if (!is_special) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "ctrl-shift-alt-p", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
|
||||
void CMD_ShowBufferList(HookParam param) {
|
||||
// @todo: maybe redo this, similar behavior but use View stored information
|
||||
// if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowBufferList) {
|
||||
// NextActiveWindowID = PrimaryWindowID;
|
||||
// return;
|
||||
// }
|
||||
BSet command_bar = GetBSet(CommandWindowID);
|
||||
command_bar.window->visible = true;
|
||||
NextActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (Buffers) {
|
||||
bool is_special = it->special || it->temp || it->is_dir || it->dont_try_to_save_in_bulk_ops;
|
||||
if (is_special) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowBufferList, "ctrl-p", "List open buffers inside the command window that you can fuzzy search over");
|
||||
|
||||
void OpenCommand(BSet active) {
|
||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||
Open(string);
|
||||
}
|
||||
|
||||
struct SearchProjectParams {
|
||||
String16 needle;
|
||||
BufferID buffer;
|
||||
};
|
||||
|
||||
void Coro_SearchProject(mco_coro *co) {
|
||||
SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx;
|
||||
|
||||
Array<BufferID> buffers = {CoCurr->arena};
|
||||
For (Buffers) {
|
||||
Add(&buffers, it->id);
|
||||
}
|
||||
|
||||
ForItem (id, buffers) {
|
||||
Buffer *it = GetBuffer(id, NULL);
|
||||
if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
Scratch scratch;
|
||||
Array<Caret> occurences = FindAll(scratch, it, param->needle);
|
||||
Buffer *out_buffer = GetBuffer(param->buffer);
|
||||
ForItem (caret, occurences) {
|
||||
Int pos = caret.range.min;
|
||||
Int line = PosToLine(it, pos);
|
||||
Range range = GetLineRangeWithoutNL(it, line);
|
||||
Int column = pos - range.min;
|
||||
String16 line_string = GetString(it, range);
|
||||
String line_string8 = ToString(scratch, line_string);
|
||||
RawAppendf(out_buffer, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
|
||||
}
|
||||
}
|
||||
CoYield(co);
|
||||
}
|
||||
}
|
||||
|
||||
float NewFuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
// try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go
|
||||
return score;
|
||||
}
|
||||
|
||||
float FuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
for (Int outer_pi = 0; outer_pi < p.len; outer_pi += 1) {
|
||||
String16 pit = Skip(p, outer_pi);
|
||||
if (IsWhitespace(At(pit, 0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float matching = 0;
|
||||
for (Int outer_si = 0; outer_si < s.len; outer_si += 1) {
|
||||
String16 sit = Skip(s, outer_si);
|
||||
if (IsWhitespace(At(sit, 0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Int si = 0;
|
||||
Int pi = 0;
|
||||
for (;si < sit.len && pi < pit.len;) {
|
||||
while (si < sit.len && IsWhitespace(sit[si])) si += 1;
|
||||
while (pi < pit.len && IsWhitespace(pit[pi])) pi += 1;
|
||||
if (pi >= pit.len) break;
|
||||
if (si >= sit.len) break;
|
||||
|
||||
if (ToLowerCase(sit[si]) == ToLowerCase(pit[pi])) {
|
||||
matching += 1.0f;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
si += 1;
|
||||
pi += 1;
|
||||
}
|
||||
}
|
||||
score += matching;
|
||||
}
|
||||
score = score / (float)s.len;
|
||||
return score;
|
||||
}
|
||||
|
||||
inline bool MergeSortCompare(FuzzyPair *a, FuzzyPair *b) {
|
||||
bool result = a->rating > b->rating;
|
||||
return result;
|
||||
}
|
||||
|
||||
Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_min, Int line_max, String16 needle) {
|
||||
ProfileFunction();
|
||||
if (line_min < 0 || line_min >= buffer->line_starts.len) return {};
|
||||
if (line_max < 0 || line_min > buffer->line_starts.len) return {};
|
||||
Array<FuzzyPair> ratings = {allocator};
|
||||
Reserve(&ratings, line_max - line_min + 4);
|
||||
for (Int i = line_min; i < line_max; i += 1) {
|
||||
String16 s = GetLineStringWithoutNL(buffer, i);
|
||||
|
||||
Int idx = 0;
|
||||
if (Seek(s, u"||>", &idx, SeekFlag_None)) {
|
||||
s = GetPrefix(s, idx);
|
||||
} else if (Seek(s, u"<||", &idx, SeekFlag_None)) {
|
||||
s = GetPrefix(s, idx);
|
||||
}
|
||||
s = Trim(s);
|
||||
|
||||
float rating = FuzzyRate(s, needle);
|
||||
Add(&ratings, {(int32_t)i, rating});
|
||||
}
|
||||
Array<FuzzyPair> temp = Copy(allocator, ratings);
|
||||
MergeSort(ratings.len, ratings.data, temp.data);
|
||||
return ratings;
|
||||
}
|
||||
|
||||
void UpdateFuzzySearchView(HookParam param) {
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
||||
uint64_t hash = HashBytes(line_string.data, line_string.len * sizeof(char16_t));
|
||||
if (active.view->prev_search_line_hash != hash) {
|
||||
active.view->prev_search_line_hash = hash;
|
||||
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, active.buffer, 1, active.buffer->line_starts.len, line_string);
|
||||
|
||||
Buffer *scratch_buff = CreateScratchBuffer(scratch, active.buffer->cap);
|
||||
RawAppend(scratch_buff, line_string);
|
||||
For(IterateInReverse(&ratings)) {
|
||||
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
|
||||
if (s.len == 0) continue;
|
||||
RawAppend(scratch_buff, u"\n");
|
||||
RawAppend(scratch_buff, s);
|
||||
}
|
||||
|
||||
Caret caret = active.view->carets[0];
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
SelectEntireBuffer(active.view);
|
||||
Replace(active.view, GetString(scratch_buff));
|
||||
active.view->carets[0] = caret;
|
||||
}
|
||||
}
|
||||
|
||||
void SetFuzzy(View *view) {
|
||||
AddCommand(&view->hooks, "Open", "ctrl-q | enter | f12", [](HookParam){
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
NextActiveWindowID = main.window->id;
|
||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||
Open(string);
|
||||
});
|
||||
AddHook(&view->hooks, HookKind_AppUpdate, "UpdateFuzzySearchView", "", UpdateFuzzySearchView);
|
||||
}
|
||||
|
||||
void LayoutCommandWindow(HookParam param) {
|
||||
auto p = param.layout;
|
||||
Rect2I copy_rect = *p.rect;
|
||||
if (!p.window->visible) {
|
||||
p.rect = ©_rect;
|
||||
}
|
||||
Int barsize = Clamp((Int)p.window->font->line_spacing*10, (Int)0, (Int)p.wx - 100);
|
||||
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
||||
}
|
||||
|
||||
void InitCommandWindow(HookParam param) {
|
||||
Window *window = CreateWind();
|
||||
CommandWindowID = window->id;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar"));
|
||||
buffer->special = true;
|
||||
buffer->no_history = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
view->special = true;
|
||||
SetFuzzy(view);
|
||||
window->active_view = view->id;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->sync_visibility_with_focus = true;
|
||||
window->lose_focus_on_escape = true;
|
||||
window->jump_history = false;
|
||||
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutCommandWindow", "", LayoutCommandWindow);
|
||||
} RegisterHook(InitCommandWindow, HookKind_AppInit, "", "Init command window");
|
||||
Reference in New Issue
Block a user