diff options
author | pommicket <pommicket@gmail.com> | 2023-03-23 14:18:26 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-03-23 14:18:26 -0400 |
commit | f338c3937686c4297daa1d24aacce719aa549ec7 (patch) | |
tree | 9b91859f3462b4f6ade85dfb55d19f49bdaa775d /macro.c | |
parent | eb088ebd059ba00735723fb394d3bfe1b3530026 (diff) |
macros are working!
Diffstat (limited to 'macro.c')
-rw-r--r-- | macro.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -1,9 +1,26 @@ #include "ted.h" +static void macro_clear(Macro *macro) { + arr_foreach_ptr(macro->actions, Action, act) { + free((char *)act->argument.string); + } + arr_free(macro->actions); + + memset(macro, 0, sizeof *macro); +} + void macro_start_recording(Ted *ted, u32 index) { if (index >= TED_MACRO_MAX) return; if (ted->executing_macro) return; + if (ted->recording_macro) { + macro_stop_recording(ted); + return; + } + + command_execute(ted, CMD_CLEAR_SELECTION, 0); + ted->recording_macro = &ted->macros[index]; + macro_clear(ted->recording_macro); } void macro_stop_recording(Ted *ted) { @@ -43,9 +60,6 @@ void macro_execute(Ted *ted, u32 index) { void macros_free(Ted *ted) { for (int i = 0; i < TED_MACRO_MAX; ++i) { Macro *macro = &ted->macros[i]; - arr_foreach_ptr(macro->actions, Action, act) { - free((char *)act->argument.string); - } - arr_free(macro->actions); + macro_clear(macro); } } |