From aff3403404ce85c19e6d0fa2afa3f0696cf922e0 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 21 Mar 2026 17:09:40 +0100 Subject: [PATCH] Add macros --- src/globals.cpp | 2 ++ src/plugin_basic_commands.cpp | 18 ++++++++++++++++++ src/text_editor.cpp | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/globals.cpp b/src/globals.cpp index a098256..30007da 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -65,6 +65,8 @@ Vec2I MouseMiddleAnchor; RandomSeed UniqueBufferNameSeed = {}; Array EventPlayback; +Array MacroPlayback; +bool RecordingMacro = false; BlockArena Perm; // clipboard diff --git a/src/plugin_basic_commands.cpp b/src/plugin_basic_commands.cpp index 2d6d6b5..31cdbfb 100644 --- a/src/plugin_basic_commands.cpp +++ b/src/plugin_basic_commands.cpp @@ -253,3 +253,21 @@ void CMD_ClearCarets() { active.view->carets.len = 1; active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0])); } RegisterCommand(CMD_ClearCarets, "escape", "Clear all carets and reset to 1 caret, also do some windowing stuff that closes things on escape"); + +void CMD_ToggleMacroRecording() { + if (RecordingMacro) { + RecordingMacro = false; + Pop(&MacroPlayback); // Remove the ctrl-m from macro playback thing + } else { + RecordingMacro = true; + MacroPlayback.len = 0; + } +} RegisterCommand(CMD_ToggleMacroRecording, "ctrl-m", "Start recording a macro"); + +void CMD_PlayMacro() { + if (RecordingMacro) { + return; + } + + For (MacroPlayback) Add(&EventPlayback, it); +} RegisterCommand(CMD_PlayMacro, "alt-m", "Start playing back a macro recording"); \ No newline at end of file diff --git a/src/text_editor.cpp b/src/text_editor.cpp index 7e9d0fc..63273fb 100644 --- a/src/text_editor.cpp +++ b/src/text_editor.cpp @@ -48,7 +48,7 @@ - [ ] Undo kinds (to enable history in fuzzy buffers) - [ ] Add undo kind. Snapshot kind, so that history is possible in weird buffers without paying a huge memory cost. The idea is that we would store the exact buffer state to replace with, editor would just save history of first line etc. -- [ ] Macros +- [x] Macros - [ ] Regex - [ ] ctags based indexing - [ ] WordComplete @@ -874,6 +874,9 @@ void MainLoop() { FrameEvents.len = 0; GetEventsForFrame(&FrameEvents); For (FrameEvents) { + if (RecordingMacro) { + Add(&MacroPlayback, it); + } #if PLUGIN_RECORD_EVENTS if (it.kind != EVENT_UPDATE && !Testing) { Serialize(EventBuffer, &it);