summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--command.c4
-rw-r--r--command.h1
-rw-r--r--macro.c22
-rw-r--r--main.c46
-rw-r--r--ted.cfg1
5 files changed, 65 insertions, 9 deletions
diff --git a/command.c b/command.c
index 59166ec..168597a 100644
--- a/command.c
+++ b/command.c
@@ -37,6 +37,7 @@ static CommandName command_names[] = {
{"select-all", CMD_SELECT_ALL},
{"select-up-blank-line", CMD_SELECT_UP_BLANK_LINE},
{"select-down-blank-line", CMD_SELECT_DOWN_BLANK_LINE},
+ {"clear-selection", CMD_CLEAR_SELECTION},
{"page-up", CMD_PAGE_UP},
{"page-down", CMD_PAGE_DOWN},
{"previous-position", CMD_PREVIOUS_POSITION},
@@ -210,6 +211,9 @@ void command_execute_ex(Ted *ted, Command c, CommandArgument full_argument, Comm
if (buffer) buffer_select_left(buffer, argument);
autocomplete_close(ted);
break;
+ case CMD_CLEAR_SELECTION:
+ if (buffer) buffer_deselect(buffer);
+ break;
case CMD_SELECT_RIGHT:
if (buffer) buffer_select_right(buffer, argument);
autocomplete_close(ted);
diff --git a/command.h b/command.h
index a17f39d..a246439 100644
--- a/command.h
+++ b/command.h
@@ -54,6 +54,7 @@ typedef enum {
CMD_SELECT_PAGE_DOWN,
CMD_SELECT_UP_BLANK_LINE,
CMD_SELECT_DOWN_BLANK_LINE,
+ CMD_CLEAR_SELECTION,
// insertion
/// insert text
diff --git a/macro.c b/macro.c
index 81f1898..14ec016 100644
--- a/macro.c
+++ b/macro.c
@@ -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);
}
}
diff --git a/main.c b/main.c
index 75a40e3..5b243a2 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
/*
-- show "recording macro..." while recording macro
+- ctrl+9/0 to inc/dec number
FUTURE FEATURES:
- better undo chaining (dechain on backspace?)
- font setting & support for multiple fonts to cover more characters
@@ -17,9 +17,7 @@ FUTURE FEATURES:
- TED_PLUGIN macro defined before including ted.h
this can remove struct definitions to guarantee forwards compatibility
- language dynamic registration
-- keyboard macros
- - ctrl+9/0 to inc/dec number would be useful here
- - with macros we can really test performance of buffer_insert_text_at_pos, etc. (which should ideally be fast)
+- with macros we can really test performance of buffer_insert_text_at_pos, etc. (which should ideally be fast)
- manual.md
- LSP request timeout
BUG REPORTS IM TO LAZY TO FILE (RIGHT NOW)
@@ -638,6 +636,9 @@ int main(int argc, char **argv) {
}
} break;
case SDL_MOUSEBUTTONDOWN: {
+ if (ted->recording_macro)
+ break; // ignore mouse input during macros
+
Uint32 button = event.button.button;
u8 times = event.button.clicks; // number of clicks
float x = (float)event.button.x, y = (float)event.button.y;
@@ -695,6 +696,9 @@ int main(int argc, char **argv) {
}
} break;
case SDL_MOUSEBUTTONUP: {
+ if (ted->recording_macro)
+ break; // ignore mouse input during macros
+
Uint8 button = event.button.button;
if (button < arr_count(ted->nmouse_releases)) {
vec2 pos = Vec2((float)event.button.x, (float)event.button.y);
@@ -704,6 +708,9 @@ int main(int argc, char **argv) {
}
} break;
case SDL_MOUSEMOTION: {
+ if (ted->recording_macro)
+ break; // ignore mouse input during macros
+
float x = (float)event.motion.x, y = (float)event.motion.y;
if (ted->drag_buffer != ted->active_buffer)
ted->drag_buffer = NULL;
@@ -727,7 +734,14 @@ int main(int argc, char **argv) {
// unfortunately, some key combinations like ctrl+minus still register as a "-" text input event
&& (key_modifier & ~KEY_MODIFIER_SHIFT) == 0) {
// insert the text
- buffer_insert_utf8_at_cursor(buffer, text);
+ {
+ CommandContext ctx = {0};
+ CommandArgument arg = {
+ .number = 0,
+ .string = text
+ };
+ command_execute_ex(ted, CMD_INSERT_TEXT, arg, ctx);
+ }
// check for trigger character
LSP *lsp = buffer_lsp(buffer);
Settings *settings = buffer_settings(buffer);
@@ -1066,6 +1080,28 @@ int main(int argc, char **argv) {
}
}
+ if (ted->recording_macro) {
+ Font *font_bold = ted->font_bold;
+ u32 bg_color = ted_active_color(ted, COLOR_ERROR_BG);
+ u32 color = ted_active_color(ted, COLOR_TEXT);
+ u8 padding = ted_active_settings(ted)->padding;
+ const char *text = "Recording macro...";
+ vec2 size = text_get_size_vec2(font_bold, text);
+ Rect r = {
+ .pos = vec2_sub(Vec2(window_width - 3 * padding, window_height - 3 * padding), size),
+ .size = vec2_add(size, Vec2(padding, padding)),
+ };
+ gl_geometry_rect(r, bg_color);
+ Rect full_screen = {
+ .pos = {0, 0},
+ .size = {window_width, window_height}
+ };
+ gl_geometry_rect(full_screen, bg_color & 0xffffff0f);
+ text_utf8_anchored(font_bold, text, window_width - 2.5f * padding, window_height - 2.5f * padding, color, ANCHOR_BOTTOM_RIGHT);
+ gl_geometry_draw();
+ text_render(font_bold);
+ }
+
ted_check_for_node_problems(ted);
#if !NDEBUG
diff --git a/ted.cfg b/ted.cfg
index f2d63f0..96cff3f 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -220,6 +220,7 @@ Ctrl+Shift+End = :select-end-of-file
Ctrl+a = :select-all
# go to previous cursor position
Ctrl+p = :previous-position
+# Ctrl+Shift+d = :clear-selection
# insertion
Tab = :tab