Save line to clipboard on right click

This commit is contained in:
Krzosa Karol
2024-08-09 09:03:11 +02:00
parent 4564e7bbc2
commit ad847a3eaa
3 changed files with 15 additions and 4 deletions

View File

@@ -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);
}
}
}

View File

@@ -22,6 +22,11 @@ void MakeSureToUseSystemAllocator_SaveInClipboard(String16 string, Array<String1
SDL_SetClipboardText(ToString(scratch, SavedClipboardString).data);
}
void SaveStringInClipboard(String16 string) {
string = Copy(GetSystemAllocator(), string);
MakeSureToUseSystemAllocator_SaveInClipboard(string);
}
void Command_Copy(View *view) {
Allocator sys_allocator = GetSystemAllocator();
Buffer *buffer = GetBuffer(view->active_buffer);

View File

@@ -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