esc

Externally Scriptable Editor

git clone git://mccd.space/esc

commit a826e62679a2bc07ce1479c32a6dbf0c28cb329f
parent 952201d38d04972ab545e077dade8c0ffac76588
Author: Marc Coquand <marc@coquand.email>
Date:   Wed, 25 Feb 2026 14:26:15 +0100

*

Diffstat:
Mmain.c | 52++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/main.c b/main.c
@@ -3,18 +3,18 @@
 #include "renderer.h"
 #include "unix_utils.h"
 #include <SDL3/SDL.h>
+#include <SDL3/SDL_clipboard.h>
 #include <SDL3/SDL_events.h>
 #include <SDL3/SDL_keycode.h>
 #include <SDL3/SDL_log.h>
 #include <SDL3/SDL_main.h>
-#include <SDL3/SDL_clipboard.h>
 #include <SDL3/SDL_mouse.h>
 #include <SDL3_ttf/SDL_ttf.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <signal.h>
 #include <unistd.h>
 
 void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
@@ -102,9 +102,11 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
 					if (!(event.key.mod & SDL_KMOD_ALT))
 						break;
 					{
-						char *sel = editor_get_selection(ed);
+						char *sel =
+						    editor_get_selection(ed);
 						if (sel) {
-							SDL_SetClipboardText(sel);
+							SDL_SetClipboardText(
+							    sel);
 							free(sel);
 						}
 					}
@@ -113,11 +115,14 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
 					if (!(event.key.mod & SDL_KMOD_ALT))
 						break;
 					{
-						char *sel = editor_get_selection(ed);
+						char *sel =
+						    editor_get_selection(ed);
 						if (sel) {
-							SDL_SetClipboardText(sel);
+							SDL_SetClipboardText(
+							    sel);
 							free(sel);
-							editor_insert_text(ed, "", true);
+							editor_insert_text(
+							    ed, "", true);
 						}
 					}
 					break;
@@ -125,9 +130,11 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
 					if (!(event.key.mod & SDL_KMOD_ALT))
 						break;
 					if (SDL_HasClipboardText()) {
-						char *text = SDL_GetClipboardText();
+						char *text =
+						    SDL_GetClipboardText();
 						if (text && *text) {
-							editor_insert_text(ed, text, true);
+							editor_insert_text(
+							    ed, text, true);
 						}
 						SDL_free(text);
 					}
@@ -226,20 +233,15 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
 							free(selection);
 						}
 					} else {
-						/* paste from primary selection */
+						/* paste from primary selection
+						 */
 						if (SDL_HasPrimarySelectionText()) {
-							char *text = SDL_GetPrimarySelectionText();
-							if (text && *text) {
-								float mx, my;
-								SDL_RenderCoordinatesFromWindow(
-								    renderer,
-								    event.button.x,
-								    event.button.y, &mx, &my);
-								editor_set_cursor_from_coords(
-								    ed, mx, my,
-								    *scroll_x, *scroll_y);
-								ed->selection_anchor = ed->cursor_idx;
-								editor_insert_text(ed, text, false);
+							char *text =
+							    SDL_GetPrimarySelectionText();
+							if (text) {
+								editor_insert_text(
+								    ed, text,
+								    false);
 							}
 							SDL_free(text);
 						}
@@ -282,9 +284,7 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
 	}
 }
 
-
-static void sig_quit(int sig)
-{
+static void sig_quit(int sig) {
 	(void)sig;
 	SDL_Event ev;
 	memset(&ev, 0, sizeof(ev));
@@ -298,7 +298,7 @@ int main(int argc, char *argv[]) {
 				SDL_HINT_OVERRIDE);
 
 	signal(SIGTERM, sig_quit);
-	signal(SIGINT,  sig_quit);
+	signal(SIGINT, sig_quit);
 
 	SDL_Init(SDL_INIT_VIDEO);
 	TTF_Init();