Even never mouse design

This commit is contained in:
Krzosa Karol
2024-08-09 09:00:04 +02:00
parent 3fb0c131f1
commit 4564e7bbc2
6 changed files with 70 additions and 25 deletions

View File

@@ -287,10 +287,36 @@ bool GlobalCommand(Event event) {
}
}
if (event.ctrl && Mouse(RIGHT)) {
if (event.ctrl && event.shift && Mouse(RIGHT)) {
MouseExecWord(event);
} else if (event.ctrl && Mouse(RIGHT)) {
MouseLoadWord(event);
} else if (event.alt && Mouse(RIGHT)) {
GoBackToLastCrumb();
} else if (Mouse(RIGHT)) {
Vec2I mouse = MouseVec2I();
Window *window = GetActiveWindow();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
if (mouse_in_document) {
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
Int p = ScreenSpaceToBufferPos(window, view, buffer, mouse);
Int saved_front = 0;
IterRemove(view->carets) {
IterRemovePrepare(view->carets);
if (InBounds(it.range, p)) {
String16 string = GetString(*buffer, it.range);
string = Copy(GetSystemAllocator(), string);
MakeSureToUseSystemAllocator_SaveInClipboard(string);
remove_item = true;
saved_front = GetFront(it);
}
}
if (view->carets.len == 0) Add(&view->carets, MakeCaret(saved_front));
}
}
// @todo: maybe move some of this stuff to window command ???
@@ -298,7 +324,6 @@ bool GlobalCommand(Event event) {
// - maybe just do the check if active window is matching the DocumentSelected window
// - if scrollbar selected then don't invoke window command
if (event.alt && Mouse(LEFT)) {
MouseLoadWord(event);
} else if (Mouse(LEFT)) { // CTRL SHIFT
Vec2I mouse = MouseVec2I();
{

View File

@@ -1,14 +1,13 @@
String16 SavedClipboardString;
Array<String16> SavedClipboardCursors;
Array<String16> SavedClipboardCarets;
void Command_Copy(View *view) {
void MakeSureToUseSystemAllocator_SaveInClipboard(String16 string, Array<String16> caret_strings = {}) {
Allocator sys_allocator = GetSystemAllocator();
Buffer *buffer = GetBuffer(view->active_buffer);
SavedClipboardCursors.allocator = sys_allocator;
if (SavedClipboardCursors.data) {
For(SavedClipboardCursors) Dealloc(sys_allocator, &it.data);
SavedClipboardCursors.len = 0;
if (SavedClipboardCarets.data) {
For(SavedClipboardCarets) Dealloc(sys_allocator, &it.data);
Dealloc(sys_allocator, &SavedClipboardCarets.data);
SavedClipboardCarets.len = {};
}
if (SavedClipboardString.data) {
@@ -16,6 +15,17 @@ void Command_Copy(View *view) {
SavedClipboardString = {};
}
SavedClipboardString = string;
SavedClipboardCarets = caret_strings;
Scratch scratch;
SDL_SetClipboardText(ToString(scratch, SavedClipboardString).data);
}
void Command_Copy(View *view) {
Allocator sys_allocator = GetSystemAllocator();
Buffer *buffer = GetBuffer(view->active_buffer);
// First, if there is no selection - select the entire line
For(view->carets) {
if (GetSize(it.range) == 0) {
@@ -25,16 +35,16 @@ void Command_Copy(View *view) {
}
}
Array<String16> caret_strings = {sys_allocator};
For(view->carets) {
String16 string = GetString(*buffer, it.range);
String16 copy = Copy(sys_allocator, string);
Add(&SavedClipboardCursors, copy);
Add(&SavedClipboardCarets, copy);
}
// @todo: maybe only add new line if there is no new line at the end, experiment with it
SavedClipboardString = Merge(sys_allocator, SavedClipboardCursors, L"\n");
Scratch scratch;
SDL_SetClipboardText(ToString(scratch, SavedClipboardString).data);
String16 final_string = Merge(sys_allocator, SavedClipboardCarets, L"\n");
MakeSureToUseSystemAllocator_SaveInClipboard(final_string, caret_strings);
}
void Command_Paste(View *view) {
@@ -50,7 +60,7 @@ void Command_Paste(View *view) {
String16 string = {string16_buffer, len};
// Regular paste
if (string != SavedClipboardString || SavedClipboardCursors.len != view->carets.len) {
if (string != SavedClipboardString || SavedClipboardCarets.len != view->carets.len) {
Array<Edit> edits = BeginEdit(scratch, buffer, view->carets);
MergeCarets(view);
For(view->carets) AddEdit(&edits, it.range, string);
@@ -62,7 +72,7 @@ void Command_Paste(View *view) {
Array<Edit> edits = BeginEdit(scratch, buffer, view->carets);
MergeCarets(view);
for (int64_t i = 0; i < view->carets.len; i += 1) {
String16 string = SavedClipboardCursors[i];
String16 string = SavedClipboardCarets[i];
Caret &it = view->carets[i];
AddEdit(&edits, it.range, string);
}

View File

@@ -887,7 +887,7 @@ void WindowCommand(Event event, Window *window, View *view) {
SetActiveWindow(titlebar->id);
}
if (Ctrl(SDLK_Q)) {
if (CtrlShift(SDLK_Q)) {
Caret caret = view->carets[0];
Range range = caret.range;
if (GetSize(caret.range) == 0) {
@@ -896,17 +896,14 @@ void WindowCommand(Event event, Window *window, View *view) {
String16 string = GetString(*buffer, range);
Command_EvalLua(view, string);
} else if (Alt(SDLK_Q)) {
} else if (Ctrl(SDLK_Q)) {
Caret caret = view->carets[0];
Range range = caret.range;
if (GetSize(caret.range) == 0) range = EncloseLoadWord(buffer, GetFront(caret));
String16 string = GetString(*buffer, range);
Open(string);
}
if (Ctrl(SDLK_W)) {
} else if (Alt(SDLK_W)) {
} else if (Alt(SDLK_Q)) {
GoBackToLastCrumb();
}
}

View File

@@ -1,4 +1,17 @@
left_mouse :: ctrl add cursor, selections work, alt load word
right_mouse :: ctrl exec word,alt go back
ctrl+q exec alt+q load
alt+w go back
alt+w go back
ctrl mleft - add cursor
ctrl shift mleft - add cursor + set selection
alt mleft -
alt ctrl mleft -
alt shift mleft -
alt mright - go back
mright - @todo: destroy pointed at selection and copy
ctrl mright - load word
shift mright -
ctrl shift mright - exec word
mmiddle -

View File

@@ -35,8 +35,8 @@ int FullScreenPositionX, FullScreenPositionY;
#include "management.cpp"
#include "window.cpp"
#include "process.cpp"
#include "commands.cpp"
#include "commands_clipboard.cpp"
#include "commands.cpp"
#include "commands_window.cpp"
#include "title_bar.cpp"

View File

@@ -184,8 +184,8 @@ void DrawWindow(Window *window, Event &event) {
}
// Underline word under mouse cursor
if (event.ctrl || event.alt) {
auto enclose_proc = event.ctrl ? EncloseExecWord : EncloseLoadWord;
if (event.ctrl) {
auto enclose_proc = event.shift ? EncloseExecWord : EncloseLoadWord;
Caret caret = view->carets[0];
Vec2I mouse = MouseVec2I();