diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 8e17f32..ed7dc9a 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -1,12 +1,3 @@ -REDESIGN and DELETE CODE -- Reduce the amount of actions needed to navigate using keyboard -- Make mouse important but much less so - -Needs to change: -- Make it more similar to sublime like editors -- Need Ctrl + P -- Clickable title bar may be cool or whatever but it's pretty bad -- Executing lua commands is clunky, need a real Ctrl+P and keybind actions, popups: remove a lot of the lua functionality, just for config files - Window, View, Buffer + flags design (or is completely new kind based approach needed for Windows/Views?) - How to make non-editable, informative, with different font size, title bar. Which might also contain tabs - How to design clickable tree view in this way? @@ -14,17 +5,9 @@ Needs to change: - How to design popup view (input field)? - How to design search view? or search and replace view? -Things I like: -- Basic editing -- Configurable Open -- Lua config files work pretty well - Splits: -- Buffer16 Buffer8? - Why constraint that name of buffer needs to be unique? For Open() and default behavior but is this required? - Try to add Tracking Allocator and rewrite the app, free all memory at the end of the app and check all is well -- move titlebar, search to splits? - Commands TODO: - Search @@ -41,31 +24,8 @@ Commands TODO: - CONSIDER AUTOMATING: CheckpointBeforeGoto - GotoBackward how to handle that in case we want to automate and create on every move? -## Hooks and bindings - -``` - -struct Hook { - String name; - String trigger; - HookFunction function; -}; - -void Command_New() { - ... -} RegisterCommand(Command_New, "ctrl-n", NOT_VISIBLE_IN_LISTING); -// How do we handle Command_Delete variations???? - -void Hook_FormatOnSave() { -} RegisterHook(Hook_FormatOnSave, "onsave"); - - -Array Hooks; - - -``` - +backlog DESIGN try to make console less special, make stuff reusable etc. DESIGN Config file versions, when loading should be checked, at the top of the file, what to do when old version? ISSUE Ctrl+Alt+Down (DuplicateLine) doesn't work on ubuntu @@ -98,7 +58,6 @@ FEATURE group history entries so the you can rollback through multiple ones at o - code sections, visual demarkation if beginning of line has a very specific text + goto next / goto prev section hotkey! - combine glyph and selection rendering -backlog - expose a coroutine based scripting enviorment where user can execute shell commands wait for them and perform actions in very linear manner - Test stdin writing code - Implement shell interaction (the valid cmd lines should start with '>' or '$', user can add more lines like this to expand the command size maybe?, if we have a case where we have a line with '>' but the last line doesn't have (just a space) then it should execute?) diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index b9be061..53b8847 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -1233,7 +1233,7 @@ API Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) { return result; } -void RunBufferTest(void *param) { +void RunBufferTest() { { Scratch scratch; Buffer buffer = {}; diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 5c9975a..56854a2 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -1085,12 +1085,12 @@ String16 FetchLoadWord(BSet set) { return string; } -void Command_Save(CommandContext *ctx) { +void Command_Save() { BSet active = GetBSet(LastActiveLayoutWindowID); SaveBuffer(active.buffer); } RegisterCommand(Command_Save, "ctrl-s"); -void Command_SaveAll(CommandContext *ctx) { +void Command_SaveAll() { For(Buffers) { if (it->file_mod_time) { SaveBuffer(it); @@ -1098,18 +1098,18 @@ void Command_SaveAll(CommandContext *ctx) { } } RegisterCommand(Command_SaveAll, "ctrl-shift-s"); -void Command_Reopen(CommandContext *ctx) { +void Command_Reopen() { BSet main = GetBSet(LastActiveLayoutWindowID); ReopenBuffer(main.buffer); ActiveWindowID = main.window->id; } RegisterCommand(Command_Reopen, ""); -void Command_New(CommandContext *ctx) { +void Command_New() { BSet main = GetBSet(LastActiveLayoutWindowID); New(main.window, ""); } RegisterCommand(Command_New, "ctrl-n"); -void Command_ToggleFullscreen(CommandContext *ctx) { +void Command_ToggleFullscreen() { if (IsInFullscreen) { SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY); SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY); @@ -1126,7 +1126,7 @@ void Command_ToggleFullscreen(CommandContext *ctx) { IsInFullscreen = !IsInFullscreen; } RegisterCommand(Command_ToggleFullscreen, "f11"); -void Command_ListCode(CommandContext *ctx) { +void Command_ListCode() { BSet main = GetBSet(LastActiveLayoutWindowID); JumpGarbageBuffer(&main); ListFilesRecursive(main.buffer, WorkDir); @@ -1135,7 +1135,7 @@ void Command_ListCode(CommandContext *ctx) { SelectRange(main.view, GetBufferEndAsRange(main.buffer)); } RegisterCommand(Command_ListCode, ""); -void Command_ShowBufferList(CommandContext *ctx) { +void Command_ShowBufferList() { BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = false; @@ -1148,7 +1148,7 @@ void Command_ShowBufferList(CommandContext *ctx) { SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); } RegisterCommand(Command_ShowBufferList, "ctrl-p"); -void Command_ListViews(CommandContext *ctx) { +void Command_ListViews() { BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = false; @@ -1163,12 +1163,12 @@ void Command_ListViews(CommandContext *ctx) { SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); } RegisterCommand(Command_ListViews, ""); -void Command_SetProjectFile(CommandContext *ctx) { +void Command_SetProjectFile() { BSet main = GetBSet(LastActiveLayoutWindowID); SetProjectFile(main.buffer); } RegisterCommand(Command_SetProjectFile, ""); -void Command_SetWorkDir(CommandContext *ctx) { +void Command_SetWorkDir() { String dir = lua_tostring(LuaState, -1); if (dir.len == 0) { BSet main = GetBSet(LastActiveLayoutWindowID); @@ -1178,27 +1178,27 @@ void Command_SetWorkDir(CommandContext *ctx) { } } RegisterCommand(Command_SetWorkDir, ""); -void Command_SetProject(CommandContext *ctx) { - Command_SetWorkDir(ctx); - Command_SetProjectFile(ctx); +void Command_SetProject() { + Command_SetWorkDir(); + Command_SetProjectFile(); } RegisterCommand(Command_SetProject, ""); -void Command_ToggleDebug(CommandContext *ctx) { +void Command_ToggleDebug() { Window *window = GetWindow(DebugWindowID); window->visible = !window->visible; } RegisterCommand(Command_ToggleDebug, "ctrl-0"); -void Command_KillProcess(CommandContext *ctx) { +void Command_KillProcess() { BSet main = GetBSet(LastActiveLayoutWindowID); KillProcess(main.view); } RegisterCommand(Command_KillProcess, ""); -void Command_KillWindow(CommandContext *ctx) { +void Command_KillWindow() { BSet main = GetBSet(LastActiveLayoutWindowID); main.window->kill = true; } RegisterCommand(Command_KillWindow, "ctrl-w"); -void Command_ShowCommands(CommandContext *ctx) { +void Command_ShowCommands() { BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = true; @@ -1211,7 +1211,7 @@ void Command_ShowCommands(CommandContext *ctx) { SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); } RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); -void Command_ShowLuaFunctions(CommandContext *ctx) { +void Command_ShowLuaFunctions() { BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = false; @@ -1224,17 +1224,17 @@ void Command_ShowLuaFunctions(CommandContext *ctx) { SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); } RegisterCommand(Command_ShowLuaFunctions, ""); -void Command_GotoBackward(CommandContext *ctx) { +void Command_GotoBackward() { BSet main = GetBSet(LastActiveLayoutWindowID); GotoBackward(main.window); } RegisterCommand(Command_GotoBackward, "alt-q | mousex1"); -void Command_GotoForward(CommandContext *ctx) { +void Command_GotoForward() { BSet main = GetBSet(LastActiveLayoutWindowID); GotoForward(main.window); } RegisterCommand(Command_GotoForward, "mousex2"); -void Command_OpenUpFolder(CommandContext *ctx) { +void Command_OpenUpFolder() { BSet main = GetBSet(LastActiveLayoutWindowID); String name = ChopLastSlash(main.buffer->name); if (EndsWith(main.buffer->name, "dirlisting")) { @@ -1243,59 +1243,59 @@ void Command_OpenUpFolder(CommandContext *ctx) { Open(name); } RegisterCommand(Command_OpenUpFolder, "ctrl-period"); -void Command_EncloseLine(CommandContext *ctx) { +void Command_EncloseLine() { BSet active = GetBSet(ActiveWindowID); EncloseLine(active.view); } RegisterCommand(Command_EncloseLine, "ctrl-l"); -void Command_SelectAll(CommandContext *ctx) { +void Command_SelectAll() { BSet active = GetBSet(ActiveWindowID); SelectEntireBuffer(active.view); active.view->update_scroll = false; } RegisterCommand(Command_SelectAll, "ctrl-a"); -void Command_Redo(CommandContext *ctx) { +void Command_Redo() { BSet active = GetBSet(ActiveWindowID); RedoEdit(active.buffer, &active.view->carets); } RegisterCommand(Command_Redo, "ctrl-shift-z"); -void Command_Undo(CommandContext *ctx) { +void Command_Undo() { BSet active = GetBSet(ActiveWindowID); UndoEdit(active.buffer, &active.view->carets); } RegisterCommand(Command_Undo, "ctrl-z"); -void Command_MakeFontLarger(CommandContext *ctx) { +void Command_MakeFontLarger() { StyleFontSize += 1; ReloadFont(StyleFont, (U32)StyleFontSize); } RegisterCommand(Command_MakeFontLarger, "ctrl-equals"); -void Command_MakeFontSmaller(CommandContext *ctx) { +void Command_MakeFontSmaller() { if (StyleFontSize > 4) { StyleFontSize -= 1; ReloadFont(StyleFont, (U32)StyleFontSize); } } RegisterCommand(Command_MakeFontSmaller, "ctrl-minus"); -void Command_Search(CommandContext *ctx) { +void Command_Search() { Window *window = GetWindow(SearchBarWindowID); window->visible = !window->visible; } RegisterCommand(Command_Search, "ctrl-f"); -void EvalCommand(CommandContext *ctx, String command) { +void EvalCommand(String command) { For (CommandFunctions) { if (it.name == command) { - it.function(ctx); + it.function(); break; } } } -void EvalCommand(CommandContext *ctx, String16 command) { +void EvalCommand(String16 command) { Scratch scratch; - EvalCommand(ctx, ToString(scratch, command)); + EvalCommand(ToString(scratch, command)); } -void FuzzySearchOpen(CommandContext *ctx, BSet active) { +void FuzzySearchOpen(BSet active) { Range range = active.view->carets[0].range; String16 string = FetchLoadWord(active); if (GetSize(range) == 0) { @@ -1313,28 +1313,28 @@ void FuzzySearchOpen(CommandContext *ctx, BSet active) { if (active.window->eval_command) { BSet main = GetBSet(LastActiveLayoutWindowID); ActiveWindowID = main.window->id; - EvalCommand(ctx, string); + EvalCommand(string); } else { Open(string); } } -void Command_Open(CommandContext *ctx) { +void Command_Open() { BSet active = GetBSet(ActiveWindowID); if (active.view->fuzzy_search) { - FuzzySearchOpen(ctx, active); + FuzzySearchOpen(active); } else { BSet active = GetBSet(LastActiveLayoutWindowID); Open(FetchLoadWord(active)); } } RegisterCommand(Command_Open, "ctrl-q"); -void Command_KillSelectedLines(CommandContext *ctx) { +void Command_KillSelectedLines() { BSet active = GetBSet(ActiveWindowID); KillSelectedLines(active.view); } RegisterCommand(Command_KillSelectedLines, "ctrl-shift-k"); -void Command_IndentSelectedLines(CommandContext *ctx) { +void Command_IndentSelectedLines() { BSet active = GetBSet(ActiveWindowID); Event event = *OnCommandEvent; bool left = false; @@ -1344,226 +1344,226 @@ void Command_IndentSelectedLines(CommandContext *ctx) { IndentSelectedLines(active.view, left); } RegisterCommand(Command_IndentSelectedLines, "ctrl-leftbracket | ctrl-rightbracket | tab | shift-tab"); -void Command_DuplicateLineDown(CommandContext *ctx) { +void Command_DuplicateLineDown() { BSet active = GetBSet(ActiveWindowID); DuplicateLine(active.view, DIR_DOWN); } RegisterCommand(Command_DuplicateLineDown, "ctrl-alt-down"); -void Command_CreateCursorDown(CommandContext *ctx) { +void Command_CreateCursorDown() { BSet active = GetBSet(ActiveWindowID); CreateCursorVertical(active.view, DIR_DOWN); } RegisterCommand(Command_CreateCursorDown, "alt-shift-down"); -void Command_SelectDownToEmptyLine(CommandContext *ctx) { +void Command_SelectDownToEmptyLine() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS); } RegisterCommand(Command_SelectDownToEmptyLine, "ctrl-shift-down"); -void Command_MoveLineDown(CommandContext *ctx) { +void Command_MoveLineDown() { BSet active = GetBSet(ActiveWindowID); MoveCaretsLine(active.view, DIR_DOWN); } RegisterCommand(Command_MoveLineDown, "alt-down"); -void Command_MoveDownToEmptyLine(CommandContext *ctx) { +void Command_MoveDownToEmptyLine() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED); } RegisterCommand(Command_MoveDownToEmptyLine, "ctrl-down"); -void Command_SelectDown(CommandContext *ctx) { +void Command_SelectDown() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS); } RegisterCommand(Command_SelectDown, "shift-down"); -void Command_MoveDown(CommandContext *ctx) { +void Command_MoveDown() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_DOWN); } RegisterCommand(Command_MoveDown, "down"); -void Command_DuplicateLineUp(CommandContext *ctx) { +void Command_DuplicateLineUp() { BSet active = GetBSet(ActiveWindowID); DuplicateLine(active.view, DIR_UP); } RegisterCommand(Command_DuplicateLineUp, "ctrl-alt-up"); -void Command_CreateCursorUp(CommandContext *ctx) { +void Command_CreateCursorUp() { BSet active = GetBSet(ActiveWindowID); CreateCursorVertical(active.view, DIR_UP); } RegisterCommand(Command_CreateCursorUp, "alt-shift-up"); -void Command_SelectUpToEmptyLine(CommandContext *ctx) { +void Command_SelectUpToEmptyLine() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS); } RegisterCommand(Command_SelectUpToEmptyLine, "ctrl-shift-up"); -void Command_MoveLineUp(CommandContext *ctx) { +void Command_MoveLineUp() { BSet active = GetBSet(ActiveWindowID); MoveCaretsLine(active.view, DIR_UP); } RegisterCommand(Command_MoveLineUp, "alt-up"); -void Command_MoveUpToEmptyLine(CommandContext *ctx) { +void Command_MoveUpToEmptyLine() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_UP, CTRL_PRESSED); } RegisterCommand(Command_MoveUpToEmptyLine, "ctrl-up"); -void Command_SelectUp(CommandContext *ctx) { +void Command_SelectUp() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS); } RegisterCommand(Command_SelectUp, "shift-up"); -void Command_MoveUp(CommandContext *ctx) { +void Command_MoveUp() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_UP); } RegisterCommand(Command_MoveUp, "up"); -void Command_BoundarySelectLeft(CommandContext *ctx) { +void Command_BoundarySelectLeft() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS); } RegisterCommand(Command_BoundarySelectLeft, "ctrl-shift-left"); -void Command_BoundaryMoveLeft(CommandContext *ctx) { +void Command_BoundaryMoveLeft() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED); } RegisterCommand(Command_BoundaryMoveLeft, "ctrl-left"); -void Command_SelectLeft(CommandContext *ctx) { +void Command_SelectLeft() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS); } RegisterCommand(Command_SelectLeft, "shift-left"); -void Command_FocusLeftWindow(CommandContext *ctx) { +void Command_FocusLeftWindow() { ActiveWindowID = SwitchWindow(DIR_LEFT)->id; } RegisterCommand(Command_FocusLeftWindow, "alt-left"); -void Command_MoveLeft(CommandContext *ctx) { +void Command_MoveLeft() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_LEFT); } RegisterCommand(Command_MoveLeft, "left"); -void Command_BoundarySelectRight(CommandContext *ctx) { +void Command_BoundarySelectRight() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS); } RegisterCommand(Command_BoundarySelectRight, "ctrl-shift-right"); -void Command_BoundaryMoveRight(CommandContext *ctx) { +void Command_BoundaryMoveRight() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED); } RegisterCommand(Command_BoundaryMoveRight, "ctrl-right"); -void Command_SelectRight(CommandContext *ctx) { +void Command_SelectRight() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS); } RegisterCommand(Command_SelectRight, "shift-right"); -void Command_FocusRightWindow(CommandContext *ctx) { +void Command_FocusRightWindow() { ActiveWindowID = SwitchWindow(DIR_RIGHT)->id; } RegisterCommand(Command_FocusRightWindow, "alt-right"); -void Command_MoveRight(CommandContext *ctx) { +void Command_MoveRight() { BSet active = GetBSet(ActiveWindowID); MoveCarets(active.view, DIR_RIGHT); } RegisterCommand(Command_MoveRight, "right"); -void Command_MoveUpAPage(CommandContext *ctx) { +void Command_MoveUpAPage() { BSet active = GetBSet(ActiveWindowID); MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS); } RegisterCommand(Command_MoveUpAPage, "pageup"); -void Command_SelectDownPage(CommandContext *ctx) { +void Command_SelectDownPage() { BSet active = GetBSet(ActiveWindowID); MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS); } RegisterCommand(Command_SelectDownPage, "shift-pagedown"); -void Command_MoveToEnd(CommandContext *ctx) { +void Command_MoveToEnd() { BSet active = GetBSet(ActiveWindowID); SelectRange(active.view, MakeRange(active.buffer->len)); } RegisterCommand(Command_MoveToEnd, "pagedown"); -void Command_MoveDownPage(CommandContext *ctx) { +void Command_MoveDownPage() { BSet active = GetBSet(ActiveWindowID); SelectRange(active.view, MakeRange(active.buffer->len)); } RegisterCommand(Command_MoveDownPage, "ctrl-pagedown"); -void Command_SelectUpPage(CommandContext *ctx) { +void Command_SelectUpPage() { BSet active = GetBSet(ActiveWindowID); MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS); } RegisterCommand(Command_SelectUpPage, "shift-pageup"); -void Command_MoveToStart(CommandContext *ctx) { +void Command_MoveToStart() { BSet active = GetBSet(ActiveWindowID); SelectRange(active.view, MakeRange(0)); } RegisterCommand(Command_MoveToStart, "ctrl-pageup"); -void Command_MoveUpPage(CommandContext *ctx) { +void Command_MoveUpPage() { BSet active = GetBSet(ActiveWindowID); MoveCursorByPageSize(active.window, DIR_UP); } RegisterCommand(Command_MoveUpPage, "pageup"); -void Command_SelectToLineStart(CommandContext *ctx) { +void Command_SelectToLineStart() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS); } RegisterCommand(Command_SelectToLineStart, "shift-home"); -void Command_MoveToLineStart(CommandContext *ctx) { +void Command_MoveToLineStart() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_LEFT); } RegisterCommand(Command_MoveToLineStart, "home"); -void Command_MoveToLineEnd(CommandContext *ctx) { +void Command_MoveToLineEnd() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_RIGHT); } RegisterCommand(Command_MoveToLineEnd, "end"); -void Command_SelectToLineEnd(CommandContext *ctx) { +void Command_SelectToLineEnd() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS); } RegisterCommand(Command_SelectToLineEnd, "shift-end"); -void Command_Delete(CommandContext *ctx) { +void Command_Delete() { BSet active = GetBSet(ActiveWindowID); Delete(active.view, DIR_LEFT); } RegisterCommand(Command_Delete, "backspace"); -void Command_DeleteBoundary(CommandContext *ctx) { +void Command_DeleteBoundary() { BSet active = GetBSet(ActiveWindowID); Delete(active.view, DIR_LEFT, SHIFT_PRESS); } RegisterCommand(Command_DeleteBoundary, "ctrl-backspace"); -void Command_DeleteForward(CommandContext *ctx) { +void Command_DeleteForward() { BSet active = GetBSet(ActiveWindowID); Delete(active.view, DIR_RIGHT); } RegisterCommand(Command_DeleteForward, "delete"); -void Command_DeleteForwardBoundary(CommandContext *ctx) { +void Command_DeleteForwardBoundary() { BSet active = GetBSet(ActiveWindowID); Delete(active.view, DIR_RIGHT, SHIFT_PRESS); } RegisterCommand(Command_DeleteForwardBoundary, "ctrl-delete"); -void Command_InsertNewLineUp(CommandContext *ctx) { +void Command_InsertNewLineUp() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_LEFT); IdentedNewLine(active.view); MoveCarets(active.view, DIR_UP); } RegisterCommand(Command_InsertNewLineUp, "ctrl-shift-enter"); -void Command_InsertNewLineDown(CommandContext *ctx) { +void Command_InsertNewLineDown() { BSet active = GetBSet(ActiveWindowID); MoveCursorToSide(active.view, DIR_RIGHT); IdentedNewLine(active.view); } RegisterCommand(Command_InsertNewLineDown, "ctrl-enter"); -void Command_SelectFuzzySearchEntry(CommandContext *ctx) { +void Command_SelectFuzzySearchEntry() { BSet active = GetBSet(ActiveWindowID); if (active.view->fuzzy_search) { - FuzzySearchOpen(ctx, active); - ctx->out_skip_rem_cmds = true; + FuzzySearchOpen(active); + SkipRemainingCommands = true; } } RegisterCommand(Command_SelectFuzzySearchEntry, "enter"); -void Command_NewLine(CommandContext *ctx) { +void Command_NewLine() { BSet active = GetBSet(ActiveWindowID); IdentedNewLine(active.view); } RegisterCommand(Command_NewLine, "enter"); -void Command_CreateCaretOnNextFind(CommandContext *ctx) { +void Command_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]); @@ -1571,17 +1571,17 @@ void Command_CreateCaretOnNextFind(CommandContext *ctx) { MergeCarets(active.buffer, &active.view->carets); } RegisterCommand(Command_CreateCaretOnNextFind, "ctrl-d"); -void Command_FocusWindow1(CommandContext *ctx) { +void Command_FocusWindow1() { ActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id; } RegisterCommand(Command_FocusWindow1, "ctrl-1"); -void Command_FocusWindow2(CommandContext *ctx) { +void Command_FocusWindow2() { Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID)); Vec2I p = GetSideOfWindow(first, DIR_RIGHT); ActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id; } RegisterCommand(Command_FocusWindow2, "ctrl-2"); -void Command_FocusWindow3(CommandContext *ctx) { +void Command_FocusWindow3() { Window *first = GetOverlappingWindow({0,0}); if (first) { Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT)); @@ -1594,7 +1594,7 @@ void Command_FocusWindow3(CommandContext *ctx) { } } RegisterCommand(Command_FocusWindow3, "ctrl-3"); -void Command_ClearCarets(CommandContext *ctx) { +void Command_ClearCarets() { BSet active = GetBSet(ActiveWindowID); active.view->carets.len = 1; active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0])); @@ -1608,3 +1608,44 @@ void Command_ClearCarets(CommandContext *ctx) { } } } RegisterCommand(Command_ClearCarets, "escape"); + +void Hook_OnDropFile(String *text) { + BSet active = GetBSet(ActiveWindowID); + WindowOpenBufferView(active.window, *text); +} RegisterHook(&OnDropFileHooks, Hook_OnDropFile); + +void Hook_OnTextInput(String *text) { + BSet active = GetBSet(ActiveWindowID); + Scratch scratch; + String16 string16 = ToString16(scratch, *text); + Replace(active.view, string16); +} RegisterHook(&OnTextInputHooks, Hook_OnTextInput); + +void Hook_PostCommandFuzzySearchUpdate(void *param) { + BSet active = GetBSet(ActiveWindowID); + if (active.view->fuzzy_search) { + if (!ProcessIsActive(active.view->id)) { + Scratch scratch; + String16 last_line_string = GetLineStringWithoutNL(active.buffer, active.buffer->line_starts.len - 1); + if (active.view->prev_search_line != last_line_string) { + active.view->prev_search_line = last_line_string; + Array ratings = FuzzySearchLines(scratch, active.buffer, 0, active.buffer->line_starts.len - 1, last_line_string); + + Buffer *temp_buffer = CreateTempBuffer(scratch, active.buffer->cap); + For(IterateInReverse(&ratings)) { + String16 s = GetLineStringWithoutNL(active.buffer, it.index); + if (s.len == 0) continue; + RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), s); + RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), u"\n"); + } + RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), last_line_string); + + Caret caret = active.view->carets[0]; + SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets); + SelectEntireBuffer(active.view); + Replace(active.view, GetString(temp_buffer)); + active.view->carets[0] = caret; + } + } + } +} RegisterHook(&PostCommandHooks, Hook_PostCommandFuzzySearchUpdate); \ No newline at end of file diff --git a/src/text_editor/commands_bindings.cpp b/src/text_editor/commands_bindings.cpp index 3a75223..1853e37 100644 --- a/src/text_editor/commands_bindings.cpp +++ b/src/text_editor/commands_bindings.cpp @@ -268,62 +268,52 @@ void OnCommand(Event event) { BSet main = GetBSet(LastActiveLayoutWindowID); BSet active = GetBSet(ActiveWindowID); + + // @todo: somehow detect in post command that buffer changed but random buffer can get changed??? Not sure + // maybe we Int buffer_change_id = active.buffer->change_id; - CommandContext ctx = {}; + String event_text = event.text; + + SkipRemainingCommands = false; For (CommandFunctions) { if (it.trigger && MatchEvent(it.trigger, &event)) { - it.function(&ctx); - MergeCarets(active.buffer, &active.view->carets); - IF_DEBUG(AssertRanges(active.view->carets)); - if (ctx.out_skip_rem_cmds) { - return; + it.function(); + if (SkipRemainingCommands) { + break; } } } - // @todo: do we need the context for commands, maybe skip cmds should be global? - // @todo: hook drop file if (event.kind == EVENT_DROP_FILE) { - WindowOpenBufferView(active.window, event.text); - } - - // @todo: hook on textinput - if (event.kind == EVENT_TEXT_INPUT) { - Scratch scratch; - String string = event.text; - String16 string16 = ToString16(scratch, string); - Replace(active.view, string16); - } - - // @todo: hook PostCommand? - // @todo: Detect if edited - if (active.view->fuzzy_search) { - if (!ProcessIsActive(active.view->id)) { - Scratch scratch; - String16 last_line_string = GetLineStringWithoutNL(active.buffer, active.buffer->line_starts.len - 1); - if (active.view->prev_search_line != last_line_string) { - active.view->prev_search_line = last_line_string; - Array ratings = FuzzySearchLines(scratch, active.buffer, 0, active.buffer->line_starts.len - 1, last_line_string); - - Buffer *temp_buffer = CreateTempBuffer(scratch, active.buffer->cap); - For(IterateInReverse(&ratings)) { - String16 s = GetLineStringWithoutNL(active.buffer, it.index); - if (s.len == 0) continue; - RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), s); - RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), u"\n"); - } - RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), last_line_string); - - Caret caret = active.view->carets[0]; - SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets); - SelectEntireBuffer(active.view); - Replace(active.view, GetString(temp_buffer)); - active.view->carets[0] = caret; + SkipRemainingCommands = false; + For (OnDropFileHooks) { + it.function(&event_text); + if (SkipRemainingCommands) { + break; + } + } + } + + if (event.kind == EVENT_TEXT_INPUT) { + SkipRemainingCommands = false; + For (OnTextInputHooks) { + it.function(&event_text); + if (SkipRemainingCommands) { + break; } } } - // :OnCommandEnding MergeCarets(active.buffer, &active.view->carets); IF_DEBUG(AssertRanges(active.view->carets)); + MergeCarets(main.buffer, &main.view->carets); + IF_DEBUG(AssertRanges(main.view->carets)); + + SkipRemainingCommands = false; + For (PostCommandHooks) { + it.function(NULL); + if (SkipRemainingCommands) { + return; + } + } } diff --git a/src/text_editor/commands_clipboard.cpp b/src/text_editor/commands_clipboard.cpp index 08c4f8f..aec1130 100644 --- a/src/text_editor/commands_clipboard.cpp +++ b/src/text_editor/commands_clipboard.cpp @@ -87,17 +87,17 @@ void ClipboardPaste(View *view) { EndEdit(buffer, &edits, &view->carets, KILL_SELECTION); } -void Command_Paste(CommandContext *ctx) { +void Command_Paste() { BSet active = GetBSet(ActiveWindowID); ClipboardPaste(active.view); } RegisterCommand(Command_Paste, "ctrl-v"); -void Command_Copy(CommandContext *ctx) { +void Command_Copy() { BSet active = GetBSet(ActiveWindowID); ClipboardCopy(active.view); } RegisterCommand(Command_Copy, "ctrl-c"); -void Command_Cut(CommandContext *ctx) { +void Command_Cut() { BSet active = GetBSet(ActiveWindowID); SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets); ClipboardCopy(active.view); diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index b4cb6b5..41c0689 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -183,21 +183,23 @@ void ReloadStyle() { StyleUndoMergeTimeout = GetStyleFloat("UndoMergeTimeout", StyleUndoMergeTimeout); } -struct CommandContext { - bool out_skip_rem_cmds; -}; - -typedef void Function(void *param); -typedef void CommandFunction(CommandContext *ctx); +typedef void Function(); +typedef void PFunction(void *param); typedef int LuaFunction(lua_State *state); struct FunctionData { String name; Function *function; }; struct LuaFunctionData { String name; LuaFunction *function; }; -struct CommandData { String name; String binding; CommandFunction *function; struct Trigger *trigger; }; +struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; }; +struct PFunctionData { String name; PFunction *function; }; +bool SkipRemainingCommands; Array CommandFunctions; Array LuaFunctions; Array TestFunctions; +Array PostCommandHooks; +Array OnTextInputHooks; +Array OnDropFileHooks; + struct Register_Function { Register_Function(Array *functions, String name, Function *f) { int64_t pos = 0; @@ -208,11 +210,16 @@ struct Register_Function { } }; #define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name) + struct Register_Lua { Register_Lua(LuaFunction *function, String name) { if (StartsWith(name, "Lua_")) name = Skip(name, 4); Add(&LuaFunctions, {name, function}); } }; -struct Register_Command { Register_Command(CommandFunction *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(&CommandFunctions, {name, binding, function}); } }; #define RegisterLua(NAME) Register_Lua RL_##NAME(NAME, #NAME) + +struct Register_Command { Register_Command(Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(&CommandFunctions, {name, binding, function}); } }; #define RegisterCommand(name, binding) Register_Command RC__##name(name, #name, binding) +struct Register_Hook { Register_Hook(Array *functions, PFunction *function, String name) { if (StartsWith(name, "Hook_")) name = Skip(name, 5); Add(functions, {name, function}); } }; +#define RegisterHook(functions, name) Register_Hook RC__##name(functions, (PFunction *)name, #name) + const int DIR_RIGHT = 0; const int DIR_LEFT = 1; const int DIR_DOWN = 2; diff --git a/src/text_editor/parser.cpp b/src/text_editor/parser.cpp index abf010d..94b2573 100644 --- a/src/text_editor/parser.cpp +++ b/src/text_editor/parser.cpp @@ -181,7 +181,7 @@ bool MatchEvent(Trigger *trigger, Event *event) { return false; } -void TestParser(void *param) { +void TestParser() { Scratch scratch; { char *cmd = "ctrl-b"; diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index fde272a..9a473b1 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -255,7 +255,7 @@ int main(int argc, char **argv) if (1) { RunArenaTest(); For (TestFunctions) { - it.function(NULL); + it.function(); } // ReportErrorf("Testing DONE\n");