esc

Externally Scriptable Editor

git clone git://mccd.space/esc

commit 945f65e2ddc9208567d9fa1cccf05cc765394727
parent 2340849aad69c1d5ba56792081e66b9f11b4a37d
Author: Marc Coquand <marc@coquand.email>
Date:   Thu, 19 Feb 2026 17:58:28 +0100

selections

Diffstat:
Meditor.c | 13+++++++++++++
Meditor.h | 2++
Mmain.c | 6++++++
3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/editor.c b/editor.c
@@ -20,6 +20,19 @@ void editor_destroy(Editor *ed) {
 	free(ed);
 }
 
+void editor_goto_pos(Editor *ed, int pos) {
+    if (pos > ed->length) {
+        ed->cursor_idx = (int)ed->length;
+    } else {
+        ed->cursor_idx = pos;
+    }
+}
+
+void editor_select_all(Editor *ed) {
+    ed->selection_anchor = 0;
+    editor_goto_pos(ed,ed->length); 
+}
+
 void editor_insert_text(Editor *ed, const char *text, bool replace) {
 	if (replace && ed->cursor_idx != ed->selection_anchor) {
 		editor_delete_range(ed, ed->cursor_idx, ed->selection_anchor);
diff --git a/editor.h b/editor.h
@@ -39,5 +39,7 @@ void editor_cursor_down(Editor *ed);
 void editor_set_cursor_from_coords(Editor *ed, float mx, float my, float scroll_x, float scroll_y);
 void editor_set_selection(Editor *ed, int anchor, int cursor);
 void editor_clear_selection(Editor *ed);
+void editor_select_all(Editor *ed);
+void editor_goto_pos(Editor *ed, int pos);
 
 #endif
diff --git a/main.c b/main.c
@@ -74,6 +74,12 @@ int main(int argc, char *argv[]) {
 						editor_newline(ed);
 						editor_clear_selection(ed);
 						break;
+					case SDLK_A:
+						if (!(event.key.mod &
+						     SDL_KMOD_ALT))
+							break;
+						editor_select_all(ed);
+						break;
 					case SDLK_B:
 						if (!(event.key.mod &
 						     SDL_KMOD_ALT) &&