diff --git a/cboard.c b/cboard.c index fa502ba..adba999 100644 --- a/cboard.c +++ b/cboard.c @@ -19,9 +19,10 @@ Cboard_error cboard_copy(Glyph const* gbuffer, Usz field_height, 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 @@ Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) { 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 @@ Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) { 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; } diff --git a/cboard.h b/cboard.h index 5e12e87..757ef12 100644 --- a/cboard.h +++ b/cboard.h @@ -12,4 +12,5 @@ Cboard_error cboard_copy(Glyph const* gbuffer, Usz field_height, 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); diff --git a/tui_main.c b/tui_main.c index f5ce6d2..74aacbc 100644 --- a/tui_main.c +++ b/tui_main.c @@ -3001,10 +3001,11 @@ int main(int argc, char** argv) { 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 @@ int main(int argc, char** argv) { } 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;