shithub: orca

Download patch

ref: af2164233545d8807410ddb1c45fd0850d8d7ed7
parent: 5197116051c4799f77e6fe22d9da3a56b16c3ba2
author: cancel <cancel@cancel.fm>
date: Fri Jan 3 20:45:54 EST 2020

Add setting of sel rect from gui cboard paste

--- a/cboard.c
+++ b/cboard.c
@@ -19,9 +19,10 @@
   return status ? Cboard_error_process_exit_error : Cboard_error_none;
 }
 
-Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) {
+Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x,
+                          Usz* out_h, Usz* out_w) {
   FILE* fp = popen("xclip -o -selection clipboard 2>/dev/null", "r");
-  Usz start_x = x;
+  Usz start_y = y, start_x = x, max_y = y, max_x = x;
   if (!fp)
     return Cboard_error_popen_failed;
   char inbuff[512];
@@ -37,6 +38,10 @@
       if (c != ' ' && y < height && x < width) {
         Glyph g = is_valid_glyph((Glyph)c) ? (Glyph)c : '.';
         gbuffer_poke(gbuffer, height, width, y, x, g);
+        if (x > max_x)
+          max_x = x;
+        if (y > max_y)
+          max_y = y;
       }
       x++;
     }
@@ -44,5 +49,7 @@
       break;
   }
   int status = pclose(fp);
+  *out_h = max_y - start_y + 1;
+  *out_w = max_x - start_x + 1;
   return status ? Cboard_error_process_exit_error : Cboard_error_none;
 }
--- a/cboard.h
+++ b/cboard.h
@@ -12,4 +12,5 @@
                          Usz field_width, Usz rect_y, Usz rect_x, Usz rect_h,
                          Usz rect_w);
 
-Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x);
+Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x,
+                          Usz* out_h, Usz* out_w);
--- a/tui_main.c
+++ b/tui_main.c
@@ -3001,10 +3001,11 @@
       if (use_gui_cboard) {
         undo_history_push(&ged_state.undo_hist, &ged_state.field,
                           ged_state.tick_num);
+        Usz pasted_h, pasted_w;
         Cboard_error cberr =
             cboard_paste(ged_state.field.buffer, ged_state.field.height,
                          ged_state.field.width, ged_state.ged_cursor.y,
-                         ged_state.ged_cursor.x);
+                         ged_state.ged_cursor.x, &pasted_h, &pasted_w);
         if (cberr) {
           undo_history_pop(&ged_state.undo_hist, &ged_state.field,
                            &ged_state.tick_num);
@@ -3018,6 +3019,11 @@
           }
           use_gui_cboard = false;
           ged_input_cmd(&ged_state, Ged_input_cmd_paste);
+        } else {
+          if (pasted_h > 0 && pasted_w > 0) {
+            ged_state.ged_cursor.h = pasted_h;
+            ged_state.ged_cursor.w = pasted_w;
+          }
         }
         ged_state.needs_remarking = true;
         ged_state.is_draw_dirty = true;