Layout window to PrimaryWindow, command documentation
This commit is contained in:
@@ -5,9 +5,10 @@ Use session 4
|
||||
- ":OpenAt C:/Work"
|
||||
- :OpenCodeAt C:/Work
|
||||
- :SetWorkDirAt C:/Work or :Set WorkDir "." ? or :Set WorkDir "C:/text_editor"
|
||||
- Maybe some convention for commands that accept arguments?
|
||||
- Delete file command
|
||||
- :Close Fuzzy search exact match doesn't match with Close
|
||||
- Maybe search everything window should have a special buffer
|
||||
- Setting variables maybe should create and modify config, commit these changes immediately? So user can change keybindings in command window and commit immediately
|
||||
|
||||
- Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep)
|
||||
- Make the equivalent of SearchProject but for cmds like !@git grep -n "@>"
|
||||
|
||||
@@ -29,7 +29,7 @@ String GetDir(Buffer *buffer) {
|
||||
}
|
||||
|
||||
String GetMainDir() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
return GetDir(main.buffer);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void Appendf(View *view, const char *fmt, ...) {
|
||||
void UIMessagef(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
RawAppendf(main.buffer, "\n %S\n :Close\n", string);
|
||||
@@ -217,7 +217,7 @@ void CenterView(WindowID window) {
|
||||
}
|
||||
|
||||
void CMD_CenterView() {
|
||||
CenterView(LastActiveLayoutWindowID);
|
||||
CenterView(PrimaryWindowID);
|
||||
} RegisterCommand(CMD_CenterView, "");
|
||||
|
||||
void MoveCursorByPageSize(Window *window, int direction, bool shift = false) {
|
||||
@@ -341,7 +341,7 @@ void GotoNextInList(Window *window, Int line_offset = 1) {
|
||||
|
||||
{
|
||||
Int idx = 0;
|
||||
String16 delim = u"|::|";
|
||||
String16 delim = u"||>";
|
||||
if (Seek(line, delim, &idx, SeekFlag_None)) {
|
||||
line = Skip(line, idx + delim.len);
|
||||
}
|
||||
@@ -425,7 +425,7 @@ View *ExecHidden(String buffer_name, String cmd, String working_dir) {
|
||||
}
|
||||
|
||||
BSet Exec(String cmd, String working_dir, bool set_active = true) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
if (set_active) {
|
||||
NextActiveWindowID = main.window->id;
|
||||
}
|
||||
@@ -436,7 +436,7 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) {
|
||||
|
||||
BSet ExecBuild(String cmd) {
|
||||
BSet build = GetBSet(BuildWindowID);
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
SelectRange(build.view, Range{});
|
||||
ResetBuffer(build.buffer);
|
||||
Exec(build.view->id, true, cmd, WorkDir);
|
||||
@@ -466,12 +466,12 @@ void CMD_Build() {
|
||||
} RegisterCommand(CMD_Build, "f1");
|
||||
|
||||
void CMD_GotoNextInList() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
GotoNextInList(main.window, 1);
|
||||
} RegisterCommand(CMD_GotoNextInList, "ctrl-e");
|
||||
|
||||
void CMD_GotoPrevInList() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
GotoNextInList(main.window, -1);
|
||||
} RegisterCommand(CMD_GotoPrevInList, "alt-e");
|
||||
|
||||
@@ -664,7 +664,7 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
|
||||
}
|
||||
|
||||
BSet Open(String path, ResolveOpenMeta meta) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main = Open(main.window, path, meta);
|
||||
return main;
|
||||
}
|
||||
@@ -676,18 +676,18 @@ BSet Open(String16 path, ResolveOpenMeta meta) {
|
||||
}
|
||||
|
||||
void CMD_Save() {
|
||||
BSet active = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet active = GetBSet(PrimaryWindowID);
|
||||
SaveBuffer(active.buffer);
|
||||
} RegisterCommand(CMD_Save, "ctrl-s");
|
||||
|
||||
void CMD_Reopen() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
ReopenBuffer(main.buffer);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Reopen, "");
|
||||
|
||||
void CMD_New() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
New(main.window, "");
|
||||
} RegisterCommand(CMD_New, "ctrl-n");
|
||||
|
||||
@@ -710,7 +710,7 @@ void CMD_ToggleFullscreen() {
|
||||
|
||||
void CMD_SetWorkDir() {
|
||||
Scratch scratch;
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
WorkDir = GetDir(main.buffer);
|
||||
For (Buffers) {
|
||||
if (it->special) {
|
||||
@@ -722,7 +722,7 @@ void CMD_SetWorkDir() {
|
||||
|
||||
String Coro_OpenCodeDir;
|
||||
void Coro_OpenCode(mco_coro *co) {
|
||||
Array<String> patterns = Split(CoCurr->arena, NonCodePatterns_EndsWith, "|");
|
||||
Array<String> patterns = Split(CoCurr->arena, Coro_OpenCodeDir, "|");
|
||||
Array<String> dirs = {CoCurr->arena};
|
||||
Add(&dirs, Coro_OpenCodeDir);
|
||||
for (int diri = 0; diri < dirs.len; diri += 1) {
|
||||
@@ -758,24 +758,24 @@ void OpenCode(String dir) {
|
||||
|
||||
void CMD_OpenCode() {
|
||||
OpenCode(WorkDir);
|
||||
} RegisterCommand(CMD_OpenCode, "");
|
||||
} RegisterCommand(CMD_OpenCode, "", "Open all code files in current WorkDir, the code files are determined through NonCodePatterns_EndsWith config variable list");
|
||||
|
||||
void CMD_KillProcess() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
KillProcess(main.view);
|
||||
} RegisterCommand(CMD_KillProcess, "");
|
||||
} RegisterCommand(CMD_KillProcess, "", "Kill process in the last active primary window");
|
||||
|
||||
void CMD_CloseWindow() {
|
||||
Close(LastActiveLayoutWindowID);
|
||||
} RegisterCommand(CMD_CloseWindow, "");
|
||||
Close(PrimaryWindowID);
|
||||
} RegisterCommand(CMD_CloseWindow, "", "Close the last active primary window");
|
||||
|
||||
void AddHook(Array<CommandData> *arr, String name, String binding, Function *function) {
|
||||
CommandData n = {name, binding, function, ParseKeyCached(binding)};
|
||||
CommandData n = {name, binding, function, "Not listing hooks anywhere currently", ParseKeyCached(binding)};
|
||||
Add(arr, n);
|
||||
}
|
||||
|
||||
void Coro_Rename(mco_coro *co) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
Buffer *buffer = main.buffer;
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
@@ -787,7 +787,7 @@ void Coro_Rename(mco_coro *co) {
|
||||
AddHook(&main.view->hooks, "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 != LastActiveLayoutWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
if (main.window->active_view != main.view->id || (main.window->id != PrimaryWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ void CMD_Rename() {
|
||||
CoRemove("Coro_Rename");
|
||||
CoData *data = CoAdd(Coro_Rename);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_Rename, "");
|
||||
} RegisterCommand(CMD_Rename, "", "Opens a UI asking for a new name of a buffer open in the last active primary window");
|
||||
|
||||
String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
||||
JumpTempBuffer(&main);
|
||||
@@ -834,7 +834,7 @@ String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
||||
AddHook(&main.view->hooks, "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 != LastActiveLayoutWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
if (main.window->active_view != main.view->id || (main.window->id != PrimaryWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -850,7 +850,7 @@ String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
||||
}
|
||||
|
||||
void Coro_Close(mco_coro *co) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
if (main.buffer->special || main.buffer->temp) {
|
||||
Close(main.view->id);
|
||||
return;
|
||||
@@ -893,15 +893,14 @@ void CMD_Close() {
|
||||
CoRemove("Coro_Close");
|
||||
CoData *data = CoAdd(Coro_Close);
|
||||
CoResume(data);
|
||||
|
||||
} RegisterCommand(CMD_Close, "ctrl-w");
|
||||
} RegisterCommand(CMD_Close, "ctrl-w", "Close open view in the last active primary window");
|
||||
|
||||
// Considerations with coroutines:
|
||||
// 1. Does scratch memory leak across Yield boundary? Or interacts badly with Yield stuff in any way?
|
||||
// 2. Are pointers and globals correct over time? Or might they get deleted etc.
|
||||
// 3. Imagine a scenario where the coroutine gets deleted before completion, will the memory leak?
|
||||
String Coro_CloseAllEx(mco_coro *co) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
Array<BufferID> buffers = {CoCurr->arena};
|
||||
For (Buffers) Add(&buffers, it->id);
|
||||
ForItem (id, buffers) {
|
||||
@@ -941,11 +940,11 @@ void CMD_Quit() {
|
||||
CoRemove("Coro_Quit");
|
||||
CoData *data = CoAdd(Coro_Quit);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_Quit, "");
|
||||
} RegisterCommand(CMD_Quit, "", "Ask user which files he would like to save and exit");
|
||||
|
||||
void CMD_QuitWithoutSaving() {
|
||||
AppIsRunning = false;
|
||||
} RegisterCommand(CMD_QuitWithoutSaving, "");
|
||||
} RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory");
|
||||
|
||||
void Coro_CloseAll(mco_coro *co) {
|
||||
Coro_CloseAllEx(co);
|
||||
@@ -955,77 +954,77 @@ void CMD_CloseAll() {
|
||||
CoRemove("Coro_CloseAll");
|
||||
CoData *data = CoAdd(Coro_CloseAll);
|
||||
CoResume(data);
|
||||
} RegisterCommand(CMD_CloseAll, "");
|
||||
} RegisterCommand(CMD_CloseAll, "", "Ask user which files to save and close all open normal views and buffers");
|
||||
|
||||
void CMD_JumpPrev() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
JumpToLastValidView(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_JumpPrev, "ctrl-tab");
|
||||
} RegisterCommand(CMD_JumpPrev, "ctrl-tab", "Go to the previous open view in primary window");
|
||||
|
||||
void CMD_Prev() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpBack(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Prev, "alt-q | mousex1");
|
||||
} 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() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpForward(main.window);
|
||||
NextActiveWindowID = main.window->id;
|
||||
} RegisterCommand(CMD_Next, "alt-shift-q | mousex2");
|
||||
} RegisterCommand(CMD_Next, "alt-shift-q | mousex2", "Go to next position, after backtracking, in the primary window");
|
||||
|
||||
void CMD_OpenUpFolder() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String name = ChopLastSlash(main.buffer->name);
|
||||
Open(name);
|
||||
} RegisterCommand(CMD_OpenUpFolder, "ctrl-period");
|
||||
} RegisterCommand(CMD_OpenUpFolder, "ctrl-period", "Open current's file directory or up directory in other cases");
|
||||
|
||||
void CMD_EncloseLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
EncloseLine(active.view);
|
||||
} RegisterCommand(CMD_EncloseLine, "ctrl-l");
|
||||
} RegisterCommand(CMD_EncloseLine, "ctrl-l", "Select the entire line on which your caret is placed");
|
||||
|
||||
void CMD_SelectAll() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SelectEntireBuffer(active.view);
|
||||
active.view->update_scroll = false;
|
||||
} RegisterCommand(CMD_SelectAll, "ctrl-a");
|
||||
} RegisterCommand(CMD_SelectAll, "ctrl-a", "Select the entire buffer");
|
||||
|
||||
void CMD_Redo() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
RedoEdit(active.buffer, &active.view->carets);
|
||||
} RegisterCommand(CMD_Redo, "ctrl-shift-z");
|
||||
} RegisterCommand(CMD_Redo, "ctrl-shift-z", "Redo after undoing changes to the buffer");
|
||||
|
||||
void CMD_Undo() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
UndoEdit(active.buffer, &active.view->carets);
|
||||
} RegisterCommand(CMD_Undo, "ctrl-z");
|
||||
} RegisterCommand(CMD_Undo, "ctrl-z", "Undo last change you made to the buffer");
|
||||
|
||||
void CMD_MakeFontLarger() {
|
||||
FontSize += 1;
|
||||
ReloadFont(Font, (U32)FontSize);
|
||||
} RegisterCommand(CMD_MakeFontLarger, "ctrl-equals");
|
||||
} RegisterCommand(CMD_MakeFontLarger, "ctrl-equals", "Increase the font size");
|
||||
|
||||
void CMD_MakeFontSmaller() {
|
||||
if (FontSize > 4) {
|
||||
FontSize -= 1;
|
||||
ReloadFont(Font, (U32)FontSize);
|
||||
}
|
||||
} RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus");
|
||||
} RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus", "Decrease the font size");
|
||||
|
||||
void CMD_OpenLoadWord() {
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 load_word = FetchLoadWord(active.view);
|
||||
// String load_word = ToString(scratch, load_word16);
|
||||
Window *window = GetWindow(LastActiveLayoutWindowID);
|
||||
window->active_goto_list = active.view->id;
|
||||
window->goto_list_pos = active.view->carets[0].range.min;
|
||||
// Window *window = GetWindow(PrimaryWindowID);
|
||||
// window->active_goto_list = active.view->id;
|
||||
// window->goto_list_pos = active.view->carets[0].range.min;
|
||||
Open(load_word);
|
||||
} RegisterCommand(CMD_OpenLoadWord, "ctrl-q");
|
||||
} RegisterCommand(CMD_OpenLoadWord, "ctrl-q", "Open a link under the caret (file link, url, command) or open the selection");
|
||||
|
||||
void CMD_KillSelectedLines() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
@@ -1289,10 +1288,10 @@ void CMD_ClearCarets() {
|
||||
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
|
||||
|
||||
if (active.window->lose_focus_on_escape && active.window->id == ActiveWindowID) {
|
||||
if (active.window->layout) {
|
||||
if (active.window->primary) {
|
||||
//
|
||||
} else {
|
||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||
NextActiveWindowID = PrimaryWindowID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1446,12 +1445,12 @@ void CMD_Set() {
|
||||
} RegisterCommand(CMD_Set, "");
|
||||
|
||||
void EvalCommandsLineByLine(BSet set) {
|
||||
WindowID save_last = LastActiveLayoutWindowID;
|
||||
WindowID save_last = PrimaryWindowID;
|
||||
WindowID save_active = ActiveWindowID;
|
||||
WindowID save_next = NextActiveWindowID;
|
||||
Caret save_caret = set.view->carets[0];
|
||||
ActiveWindowID = set.window->id;
|
||||
LastActiveLayoutWindowID = set.window->id;
|
||||
PrimaryWindowID = set.window->id;
|
||||
NextActiveWindowID = set.window->id;
|
||||
for (Int i = 0; i < set.buffer->line_starts.len; i += 1) {
|
||||
Int pos = GetLineRangeWithoutNL(set.buffer, i).min;
|
||||
@@ -1468,13 +1467,13 @@ void EvalCommandsLineByLine(BSet set) {
|
||||
Open(string);
|
||||
}
|
||||
set.view->carets[0] = save_caret;
|
||||
LastActiveLayoutWindowID = save_last;
|
||||
PrimaryWindowID = save_last;
|
||||
ActiveWindowID = save_active;
|
||||
NextActiveWindowID = save_next;
|
||||
}
|
||||
|
||||
void CMD_EvalCommandsLineByLine() {
|
||||
BSet set = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet set = GetBSet(PrimaryWindowID);
|
||||
EvalCommandsLineByLine(set);
|
||||
} RegisterCommand(CMD_EvalCommandsLineByLine, "");
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ void DrawWindow(Window *window, Event &event) {
|
||||
SetScissor(screen_rect);
|
||||
|
||||
bool is_active = window->id == ActiveWindowID;
|
||||
bool active_layed_out_doc = window->id == LastActiveLayoutWindowID;
|
||||
bool active_layed_out_doc = window->id == PrimaryWindowID;
|
||||
|
||||
Color color_whitespace_during_selection = SelectedWhitespaceColor;
|
||||
Color color_background = BackgroundColor;
|
||||
|
||||
@@ -38,7 +38,7 @@ BufferID BuildBufferID;
|
||||
|
||||
WindowID NextActiveWindowID;
|
||||
WindowID ActiveWindowID;
|
||||
WindowID LastActiveLayoutWindowID;
|
||||
WindowID PrimaryWindowID;
|
||||
WindowID ScrollbarSelected = {-1};
|
||||
WindowID DocumentSelected = {-1};
|
||||
WindowID ResizerSelected = {-1};
|
||||
|
||||
@@ -88,7 +88,7 @@ void SetMouseCursor(Event event) {
|
||||
|
||||
if (ResizerSelected.id != -1) {
|
||||
Window *window = GetWindow(ResizerSelected);
|
||||
if (window->layout) {
|
||||
if (window->primary) {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
} else {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
@@ -98,7 +98,7 @@ void SetMouseCursor(Event event) {
|
||||
|
||||
if (ResizerHover.id != -1) {
|
||||
Window *window = GetWindow(ResizerHover);
|
||||
if (window->layout) {
|
||||
if (window->primary) {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
} else {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
@@ -256,7 +256,7 @@ void OnCommand(Event event) {
|
||||
ResizerSelected.id = {-1};
|
||||
} else if (ResizerSelected.id != -1) {
|
||||
Window *window = GetWindow(ResizerSelected);
|
||||
if (window->layout) {
|
||||
if (window->primary) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
Int offx = mouse.x - window->resizer_rect.min.x;
|
||||
window->weight += (double)offx / (double)WindowCalcEvenResizerValue(event.xwindow);
|
||||
@@ -403,7 +403,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
|
||||
bool executed = false;
|
||||
@@ -630,7 +630,7 @@ void Update(Event event) {
|
||||
ActiveWindowID = NextActiveWindowID;
|
||||
Window *window = GetWindow(ActiveWindowID, NULL);
|
||||
if (window == NULL || window->visible == false) {
|
||||
ActiveWindowID = NextActiveWindowID = LastActiveLayoutWindowID;
|
||||
ActiveWindowID = NextActiveWindowID = PrimaryWindowID;
|
||||
window = GetWindow(ActiveWindowID, NULL);
|
||||
if (window == NULL) {
|
||||
ActiveWindowID = NullWindowID;
|
||||
@@ -653,10 +653,10 @@ void Update(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ActiveWindowID != LastActiveLayoutWindowID) {
|
||||
if (ActiveWindowID != PrimaryWindowID) {
|
||||
Window *window = GetWindow(ActiveWindowID, NULL);
|
||||
if (window->layout) {
|
||||
LastActiveLayoutWindowID = ActiveWindowID;
|
||||
if (window->primary) {
|
||||
PrimaryWindowID = ActiveWindowID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ struct Register_Function {
|
||||
};
|
||||
#define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name)
|
||||
|
||||
struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding) { if (StartsWith(name, "CMD_")) name = Skip(name, sizeof("CMD_") - 1); Add(fucs, {name, binding, function}); } };
|
||||
#define RegisterCommand(name, binding) Register_Command RC__##name(&CommandFunctions, name, #name, binding)
|
||||
struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding, String doc = "") { if (StartsWith(name, "CMD_")) name = Skip(name, sizeof("CMD_") - 1); Add(fucs, {name, binding, function, doc}); } };
|
||||
#define RegisterCommand(name, ...) Register_Command RC__##name(&CommandFunctions, name, #name, __VA_ARGS__)
|
||||
|
||||
const int DIR_RIGHT = 0;
|
||||
const int DIR_LEFT = 1;
|
||||
|
||||
@@ -126,7 +126,7 @@ String16 FetchFuzzyViewLoadLine(View *view) {
|
||||
string = GetLineStringWithoutNL(buffer, line);
|
||||
|
||||
Int idx = 0;
|
||||
String16 delim = u"|::|";
|
||||
String16 delim = u"||>";
|
||||
if (Seek(string, delim, &idx, SeekFlag_None)) {
|
||||
string = Skip(string, idx + delim.len);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ struct ViewID { Int id; View *o; };
|
||||
|
||||
typedef void Function();
|
||||
struct FunctionData { String name; Function *function; };
|
||||
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
|
||||
struct CommandData { String name; String binding; Function *function; String doc; struct Trigger *trigger; };
|
||||
|
||||
enum ViewKind {
|
||||
ViewKind_Normal,
|
||||
|
||||
@@ -7,7 +7,7 @@ Window *CreateWind() {
|
||||
Window *w = AllocType(allocator, Window);
|
||||
w->font = &PrimaryFont;
|
||||
w->visible = true;
|
||||
w->layout = true;
|
||||
w->primary = true;
|
||||
w->draw_scrollbar = true;
|
||||
w->draw_line_numbers = true;
|
||||
w->draw_line_highlight = true;
|
||||
@@ -134,7 +134,7 @@ double WindowCalcEvenResizerValue(Int screen_size_x, Int *out_count = NULL) {
|
||||
double w = 0;
|
||||
Int c = 0;
|
||||
ForItem(n, Windows) {
|
||||
if (n->layout) {
|
||||
if (n->primary) {
|
||||
w += n->weight;
|
||||
c += 1;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
|
||||
int i = 0;
|
||||
ForItem(n, Windows) {
|
||||
if (!n->layout) {
|
||||
if (!n->primary) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ struct Window {
|
||||
uint32_t secondary_window_style : 1;
|
||||
uint32_t draw_line_highlight : 1;
|
||||
uint32_t visible : 1;
|
||||
uint32_t layout : 1;
|
||||
uint32_t primary : 1;
|
||||
uint32_t close : 1;
|
||||
uint32_t sync_visibility_with_focus : 1;
|
||||
uint32_t lose_focus_on_escape : 1;
|
||||
|
||||
@@ -11,7 +11,7 @@ void BuildWindowInit() {
|
||||
window->active_view = view->id;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->layout = false;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
void CMD_ShowCommands() {
|
||||
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowCommands) {
|
||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||
NextActiveWindowID = PrimaryWindowID;
|
||||
return;
|
||||
}
|
||||
ProfileFunction();
|
||||
@@ -13,15 +13,18 @@ void CMD_ShowCommands() {
|
||||
if (it.name == "OpenCommand") {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n:%S", it.name);
|
||||
RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding);
|
||||
if (it.doc.len) {
|
||||
RawAppendf(command_bar.buffer, " |::| %S", it.doc);
|
||||
}
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p");
|
||||
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window");
|
||||
|
||||
void CMD_ShowDebugBufferList() {
|
||||
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) {
|
||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||
NextActiveWindowID = PrimaryWindowID;
|
||||
return;
|
||||
}
|
||||
ProfileFunction();
|
||||
@@ -35,11 +38,11 @@ void CMD_ShowDebugBufferList() {
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "");
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
|
||||
void CMD_ShowBufferList() {
|
||||
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowBufferList) {
|
||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||
NextActiveWindowID = PrimaryWindowID;
|
||||
return;
|
||||
}
|
||||
ProfileFunction();
|
||||
@@ -53,7 +56,7 @@ void CMD_ShowBufferList() {
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowBufferList, "ctrl-p");
|
||||
} RegisterCommand(CMD_ShowBufferList, "ctrl-p", "List open buffers inside the command window that you can fuzzy search over");
|
||||
|
||||
void OpenCommand(BSet active) {
|
||||
ProfileFunction();
|
||||
@@ -63,13 +66,13 @@ void OpenCommand(BSet active) {
|
||||
|
||||
void CMD_CommandWindowOpen() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
NextActiveWindowID = main.window->id;
|
||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||
// if (active.view->kind == ViewKind_ActiveSearch) {
|
||||
main.window->active_goto_list = active.view->id;
|
||||
main.window->goto_list_pos = active.view->carets[0].range.min;
|
||||
// }
|
||||
if (active.view->kind == ViewKind_ActiveSearch) {
|
||||
main.window->active_goto_list = active.view->id;
|
||||
main.window->goto_list_pos = active.view->carets[0].range.min;
|
||||
}
|
||||
Open(string);
|
||||
}
|
||||
|
||||
@@ -120,8 +123,9 @@ Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_
|
||||
String16 s = GetLineStringWithoutNL(buffer, i);
|
||||
|
||||
Int idx = 0;
|
||||
String16 delim = u"|::|";
|
||||
if (Seek(s, delim, &idx, SeekFlag_None)) {
|
||||
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);
|
||||
@@ -155,7 +159,7 @@ void Coro_SearchProject(mco_coro *co) {
|
||||
Int line = PosToLine(it, pos);
|
||||
String16 line_string = GetLineStringWithoutNL(it, line);
|
||||
String line_string8 = ToString(scratch, line_string);
|
||||
RawAppendf(out_buffer, "%S |::| %S:%lld\n", line_string8, it->name, (long long)line + 1);
|
||||
RawAppendf(out_buffer, "%S ||> %S:%lld\n", line_string8, it->name, (long long)line + 1);
|
||||
}
|
||||
}
|
||||
CoYield(co);
|
||||
@@ -163,7 +167,7 @@ void Coro_SearchProject(mco_coro *co) {
|
||||
}
|
||||
|
||||
void CMD_ReplaceAll() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String16 string = FetchLoadWord(main.view);
|
||||
Scratch scratch;
|
||||
Array<String16> parts = Split(scratch, string, u"@>");
|
||||
@@ -183,7 +187,7 @@ void CMD_ReplaceAll() {
|
||||
SelectAllOccurences(view, needle);
|
||||
Replace(view, replace);
|
||||
}
|
||||
} RegisterCommand(CMD_ReplaceAll, "");
|
||||
} RegisterCommand(CMD_ReplaceAll, "", "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");
|
||||
|
||||
void FuzzySearchViewUpdate() {
|
||||
ProfileFunction();
|
||||
@@ -240,13 +244,13 @@ void FuzzySearchViewUpdate() {
|
||||
}
|
||||
|
||||
void CMD_SearchProject() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
main.view->kind = ViewKind_ActiveSearch;
|
||||
AddHook(&main.view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen);
|
||||
main.buffer->no_history = true;
|
||||
} RegisterCommand(CMD_SearchProject, "ctrl-shift-f");
|
||||
} RegisterCommand(CMD_SearchProject, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
|
||||
|
||||
void SetFuzzy(View *view) {
|
||||
view->kind = ViewKind_FuzzySearch;
|
||||
@@ -267,7 +271,7 @@ void CommandWindowInit() {
|
||||
window->draw_scrollbar = false;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = true;
|
||||
window->layout = false;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->sync_visibility_with_focus = true;
|
||||
window->lose_focus_on_escape = true;
|
||||
|
||||
@@ -5,7 +5,7 @@ void DebugWindowInit() {
|
||||
window->draw_scrollbar = false;
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
window->layout = false;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
@@ -43,7 +43,7 @@ void DebugWindowUpdate() {
|
||||
return;
|
||||
}
|
||||
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
|
||||
Scratch scratch;
|
||||
String s = Format(scratch, "wid: %d\nvid: %d\nbid: %d\nframe: %lld\n", (int)main.window->id.id, (int)main.view->id.id, (int)main.buffer->id.id, (long long)FrameID);
|
||||
|
||||
@@ -15,12 +15,12 @@ void CMD_Search() {
|
||||
} RegisterCommand(CMD_Search, "ctrl-f");
|
||||
|
||||
void SearchWindowFindNext(bool forward = true) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet set = GetBSet(SearchWindowID);
|
||||
String16 seek = GetString(set.buffer, GetRange(set.buffer));
|
||||
Find(main.view, seek, forward);
|
||||
main.window->search_bar_anchor = main.view->carets[0];
|
||||
CenterView(LastActiveLayoutWindowID);
|
||||
CenterView(PrimaryWindowID);
|
||||
}
|
||||
|
||||
void CMD_SearchNextInSearch() {
|
||||
@@ -40,7 +40,7 @@ void CMD_SearchPrev() {
|
||||
} RegisterCommand(CMD_SearchPrev, "shift-f3");
|
||||
|
||||
void CMD_SearchAll() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet set = GetBSet(SearchWindowID);
|
||||
String16 needle = GetString(set.buffer, GetRange(set.buffer));
|
||||
SelectAllOccurences(main.view, needle);
|
||||
@@ -58,7 +58,7 @@ void CMD_ToggleSearchWordBoundary() {
|
||||
void SearchWindowUpdate() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
if (active.window->id == SearchWindowID && active.buffer->begin_frame_change_id != active.buffer->change_id) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
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));
|
||||
@@ -92,7 +92,7 @@ void SearchWindowInit() {
|
||||
window->draw_scrollbar = false;
|
||||
window->secondary_window_style = true;
|
||||
window->draw_line_highlight = false;
|
||||
window->layout = false;
|
||||
window->primary = false;
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
|
||||
@@ -11,7 +11,7 @@ void StatusWindowInit() {
|
||||
window->draw_scrollbar = false;
|
||||
window->draw_line_highlight = true;
|
||||
window->secondary_window_style = true;
|
||||
window->layout = false;
|
||||
window->primary = false;
|
||||
window->jump_history = false;
|
||||
window->lose_focus_on_escape = true;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ void StatusWindowUpdate() {
|
||||
ProfileFunction();
|
||||
Window *status_bar_window = GetWindow(StatusBarWindowID, NULL);
|
||||
Scratch scratch;
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet title = GetBSet(status_bar_window);
|
||||
title.view->scroll.y = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user