From ad847a3eaa14368f360c92d6821b8042f9888907 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 9 Aug 2024 09:03:11 +0200 Subject: [PATCH] Save line to clipboard on right click --- src/text_editor/commands.cpp | 12 +++++++++--- src/text_editor/commands_clipboard.cpp | 5 +++++ src/text_editor/notes_bindings | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 00777cd..9211cb6 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -302,20 +302,26 @@ bool GlobalCommand(Event event) { Buffer *buffer = GetBuffer(view->active_buffer); Int p = ScreenSpaceToBufferPos(window, view, buffer, mouse); - Int saved_front = 0; + Int saved_front = -1; IterRemove(view->carets) { IterRemovePrepare(view->carets); if (InBounds(it.range, p)) { String16 string = GetString(*buffer, it.range); - string = Copy(GetSystemAllocator(), string); - MakeSureToUseSystemAllocator_SaveInClipboard(string); + SaveStringInClipboard(string); remove_item = true; saved_front = GetFront(it); } } if (view->carets.len == 0) Add(&view->carets, MakeCaret(saved_front)); + + if (saved_front == -1) { + Int line = PosToLine(*buffer, p); + Range line_range = GetLineRangeWithoutNL(*buffer, line); + String16 string = GetString(*buffer, line_range); + SaveStringInClipboard(string); + } } } diff --git a/src/text_editor/commands_clipboard.cpp b/src/text_editor/commands_clipboard.cpp index 364840a..0d69ef2 100644 --- a/src/text_editor/commands_clipboard.cpp +++ b/src/text_editor/commands_clipboard.cpp @@ -22,6 +22,11 @@ void MakeSureToUseSystemAllocator_SaveInClipboard(String16 string, Arrayactive_buffer); diff --git a/src/text_editor/notes_bindings b/src/text_editor/notes_bindings index dd634c3..eafa19f 100644 --- a/src/text_editor/notes_bindings +++ b/src/text_editor/notes_bindings @@ -10,7 +10,7 @@ alt mleft - alt ctrl mleft - alt shift mleft - alt mright - go back -mright - @todo: destroy pointed at selection and copy +mright - destroy pointed at selection and copy ctrl mright - load word shift mright - ctrl shift mright - exec word