From 3ff2deaf6f5e5459998621f7a0cc75ae542d836c Mon Sep 17 00:00:00 2001 From: Matheus Santos Date: Thu, 14 Sep 2023 16:59:33 -0300 Subject: [PATCH 1/3] Text Editor: Copy/Cut Line --- source/blender/editors/space_text/text_ops.cc | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index d2ae7b557f0..532d9ad9e64 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -1083,15 +1083,15 @@ static void txt_copy_clipboard(Text *text) char *buf; if (!txt_has_sel(text)) { - return; + buf = static_cast(MEM_mallocN(text->curl->len + 1, "Clipboard")); + BLI_strncpy(buf, text->curl->line, text->curl->len + 1); + } + else { + buf = txt_sel_to_buf(text, nullptr); } - buf = txt_sel_to_buf(text, nullptr); - - if (buf) { - WM_clipboard_text_set(buf, false); - MEM_freeN(buf); - } + WM_clipboard_text_set(buf, false); + MEM_freeN(buf); } static int text_copy_exec(bContext *C, wmOperator * /*op*/) @@ -1131,6 +1131,12 @@ static int text_cut_exec(bContext *C, wmOperator * /*op*/) txt_copy_clipboard(text); ED_text_undo_push_init(C); + if (!txt_has_sel(text)) { + /* Select the current line */ + text->curl = text->curl->prev; + text->curc = text->curl->len; + text->selc = text->sell->len; + } txt_delete_selected(text); text_update_cursor_moved(C); -- 2.30.2 From c58c26c2a90e031f1438ae0e689a8754fe6dc226 Mon Sep 17 00:00:00 2001 From: Matheus Santos Date: Thu, 14 Sep 2023 17:06:01 -0300 Subject: [PATCH 2/3] Using MEM_cnew_array --- source/blender/editors/space_text/text_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 532d9ad9e64..903d31de642 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -1083,7 +1083,7 @@ static void txt_copy_clipboard(Text *text) char *buf; if (!txt_has_sel(text)) { - buf = static_cast(MEM_mallocN(text->curl->len + 1, "Clipboard")); + buf = MEM_cnew_array(text->curl->len + 1, AT); BLI_strncpy(buf, text->curl->line, text->curl->len + 1); } else { -- 2.30.2 From 6db63450784237dc0cd437d9e44bdbfd9852dba8 Mon Sep 17 00:00:00 2001 From: Matheus Santos Date: Thu, 14 Sep 2023 17:07:03 -0300 Subject: [PATCH 3/3] Update comment to follow the style guide --- source/blender/editors/space_text/text_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 903d31de642..76300a9fdb6 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -1132,7 +1132,7 @@ static int text_cut_exec(bContext *C, wmOperator * /*op*/) ED_text_undo_push_init(C); if (!txt_has_sel(text)) { - /* Select the current line */ + /* Select the current line. */ text->curl = text->curl->prev; text->curc = text->curl->len; text->selc = text->sell->len; -- 2.30.2