esc
Externally Scriptable Editor
git clone git://mccd.space/esc
| Log | Files | Refs | README |
commit e51fda723d45058942f28fd5e81edb66e9a2299e parent ec21c9cab3d96e53c1a678576770a3d33dd3297d Author: Marc Coquand <marc@coquand.email> Date: Wed, 25 Feb 2026 15:19:37 +0100 test out the new clipboard changes Diffstat:
| M | main.c | | | 28 | +++++++++++++++++++++++++++- |
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
@@ -22,6 +22,7 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
bool *is_dragging) {
SDL_Event event;
char *cmd;
+ static char *last_primary_selection = NULL;
if (SDL_WaitEvent(&event)) {
do {
@@ -238,6 +239,7 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
if (SDL_HasPrimarySelectionText()) {
char *text =
SDL_GetPrimarySelectionText();
+ SDL_Log("Got primary selection: %s", text ? text : "(null)");
if (text) {
editor_insert_text(
ed, text,
@@ -277,9 +279,33 @@ void handle_events(Editor *ed, SDL_Renderer *renderer, float *scroll_x,
if (editor_has_selection(ed)) {
char *sel = editor_get_selection(ed);
if (sel) {
- SDL_SetPrimarySelectionText(sel);
+ // Only update primary selection if it changed
+ bool selection_changed = (last_primary_selection == NULL ||
+ strcmp(last_primary_selection, sel) != 0);
+
+ if (selection_changed) {
+ SDL_SetPrimarySelectionText(sel);
+ SDL_Log("Set primary selection: %s", sel);
+
+ // Also try to set it using wl-copy as a fallback for external tools
+ char cmd[1024];
+ snprintf(cmd, sizeof(cmd), "wl-copy --primary '%s'", sel);
+ unix_exec_command(cmd, NULL);
+
+ // Update the last selection
+ if (last_primary_selection) {
+ free(last_primary_selection);
+ }
+ last_primary_selection = strdup(sel);
+ }
free(sel);
}
+ } else {
+ // No selection, clear the last selection
+ if (last_primary_selection) {
+ free(last_primary_selection);
+ last_primary_selection = NULL;
+ }
}
}
}