Refactor WindowCommands
This commit is contained in:
@@ -188,354 +188,3 @@ void MouseLoadWord(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalCommand(Event event) {
|
|
||||||
ProfileFunction();
|
|
||||||
bool run_window_command = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Window cursor setting
|
|
||||||
//
|
|
||||||
Scratch scratch;
|
|
||||||
Array<Int> order = GetWindowZOrder(scratch);
|
|
||||||
{
|
|
||||||
static SDL_Cursor *SDL_MouseCursor;
|
|
||||||
if (SDL_MouseCursor) {
|
|
||||||
SDL_DestroyCursor(SDL_MouseCursor);
|
|
||||||
SDL_MouseCursor = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
For(order) {
|
|
||||||
Window *window = Windows[it].o;
|
|
||||||
if (!window->visible) continue;
|
|
||||||
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
|
|
||||||
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
|
|
||||||
|
|
||||||
if (!IsDocumentSelectionValid() && (mouse_in_scrollbar || IsScrollbarSelectionValid())) {
|
|
||||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
|
||||||
SDL_SetCursor(SDL_MouseCursor);
|
|
||||||
break;
|
|
||||||
} else if (mouse_in_total || IsDocumentSelectionValid()) {
|
|
||||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
|
||||||
SDL_SetCursor(SDL_MouseCursor);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SDL_MouseCursor) {
|
|
||||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
|
||||||
SDL_SetCursor(SDL_MouseCursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle wheel scrolling
|
|
||||||
if (event.wheel.x || event.wheel.y) {
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
|
|
||||||
For(order) {
|
|
||||||
Window *window = Windows[it].o;
|
|
||||||
if (!window->visible) continue;
|
|
||||||
|
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
|
||||||
if (mouse_in_window) {
|
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
view->scroll.y -= (Int)(event.wheel.y * 48);
|
|
||||||
view->scroll.x += (Int)(event.wheel.x * 48);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle selected window scrollbar
|
|
||||||
// @note: the order here assumes that we won't run this code on the
|
|
||||||
// same event as the scroll was pressed
|
|
||||||
if (IsScrollbarSelectionValid() && Mouse(LEFT_UP)) {
|
|
||||||
Assert(DocumentSelected.id == -1);
|
|
||||||
ScrollbarSelected.id = -1;
|
|
||||||
} else if (IsScrollbarSelectionValid()) {
|
|
||||||
// :ScrollbarImprovement
|
|
||||||
// @todo: it generally works ok but it moves the scrollbar a bit on click
|
|
||||||
// when mouse is not even moving
|
|
||||||
Assert(DocumentSelected.id == -1);
|
|
||||||
Window *window = GetWindow(ScrollbarSelected);
|
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
Vec2 mouse_vec2 = MouseVec2();
|
|
||||||
Scroller s = ComputeScrollerRect(window);
|
|
||||||
double size_y = (double)GetSize(window->scrollbar_rect).y;
|
|
||||||
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
|
||||||
double v = p / size_y;
|
|
||||||
v = v + (window->mouse_scroller_offset);
|
|
||||||
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
|
||||||
run_window_command = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DocumentSelected != ActiveWindow) {
|
|
||||||
DocumentSelected.id = -1;
|
|
||||||
} else if (IsDocumentSelectionValid() && MouseUp()) {
|
|
||||||
Assert(ScrollbarSelected.id == -1);
|
|
||||||
DocumentSelected.id = -1;
|
|
||||||
} else if (IsDocumentSelectionValid()) {
|
|
||||||
Assert(ScrollbarSelected.id == -1);
|
|
||||||
BSet selected = GetBSet(DocumentSelected);
|
|
||||||
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
// Special case for full-screen where we can have document
|
|
||||||
// aligned with monitor screen in which case mouse cursor cannot
|
|
||||||
// be smaller then 0 which means we cannot scroll
|
|
||||||
if (mouse.y == 0 && selected.window->document_rect.min.y == 0) {
|
|
||||||
float x, y;
|
|
||||||
SDL_GetGlobalMouseState(&x, &y);
|
|
||||||
if (y == 0) {
|
|
||||||
mouse.y = -10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
|
|
||||||
Caret &caret = selected.view->carets[0];
|
|
||||||
|
|
||||||
caret = SetFrontWithAnchor(caret, DocumentRangeAnchor, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set active window on click
|
|
||||||
if (MousePress()) {
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
For(order) {
|
|
||||||
Window *window = Windows[it].o;
|
|
||||||
if (!window->visible) continue;
|
|
||||||
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
|
||||||
if (mouse_in_document) {
|
|
||||||
ActiveWindow = window->id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Mouse(MIDDLE)) {
|
|
||||||
MouseExecWord(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.ctrl && event.shift && Mouse(RIGHT)) {
|
|
||||||
GotoForward(GetActiveMainSet().window);
|
|
||||||
} else if (event.alt && event.ctrl && Mouse(RIGHT)) {
|
|
||||||
} else if (event.ctrl && Mouse(RIGHT)) {
|
|
||||||
GotoBackward(GetActiveMainSet().window);
|
|
||||||
} else if (event.alt && Mouse(RIGHT)) {
|
|
||||||
} else if (Mouse(RIGHT)) {
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
BSet active = GetActiveSet();
|
|
||||||
bool mouse_in_document = CheckCollisionPointRec(mouse, active.window->document_rect);
|
|
||||||
if (mouse_in_document) {
|
|
||||||
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
|
||||||
Int saved_front = -1;
|
|
||||||
|
|
||||||
IterRemove(active.view->carets) {
|
|
||||||
IterRemovePrepare(active.view->carets);
|
|
||||||
if (InBounds(it.range, p)) {
|
|
||||||
String16 string = GetString(active.buffer, it.range);
|
|
||||||
SaveStringInClipboard(string);
|
|
||||||
|
|
||||||
remove_item = true;
|
|
||||||
saved_front = GetFront(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (active.view->carets.len == 0) Add(&active.view->carets, MakeCaret(saved_front));
|
|
||||||
|
|
||||||
if (saved_front == -1) {
|
|
||||||
Int line = PosToLine(active.buffer, p);
|
|
||||||
Range line_range = GetLineRangeWithoutNL(active.buffer, line);
|
|
||||||
String16 string = GetString(active.buffer, line_range);
|
|
||||||
SaveStringInClipboard(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo: maybe move some of this stuff to window command ???
|
|
||||||
// for now let's leave it because we are relaying on global state
|
|
||||||
// - maybe just do the check if active window is matching the DocumentSelected window
|
|
||||||
// - if scrollbar selected then don't invoke window command
|
|
||||||
if (event.ctrl && event.shift && Mouse(LEFT)) {
|
|
||||||
MouseExecWord(event);
|
|
||||||
} else if (event.ctrl && Mouse(LEFT)) {
|
|
||||||
MouseLoadWord(event);
|
|
||||||
} else if (Mouse(LEFT)) { // CTRL SHIFT
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
{
|
|
||||||
Assert(ScrollbarSelected.id == -1);
|
|
||||||
Assert(DocumentSelected.id == -1);
|
|
||||||
|
|
||||||
BSet active = GetActiveSet();
|
|
||||||
bool mouse_in_document = CheckCollisionPointRec(mouse, active.window->document_rect);
|
|
||||||
bool mouse_in_line_numbers = CheckCollisionPointRec(mouse, active.window->line_numbers_rect);
|
|
||||||
if (mouse_in_document || mouse_in_line_numbers) {
|
|
||||||
DocumentSelected = active.window->id;
|
|
||||||
|
|
||||||
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
|
||||||
if (event.alt) Insert(&active.view->carets, MakeCaret(p, p), 0);
|
|
||||||
if (!event.alt && !event.shift) active.view->carets.len = 1;
|
|
||||||
|
|
||||||
Caret &caret = active.view->carets[0];
|
|
||||||
if (event.shift) {
|
|
||||||
if (p <= caret.range.min) {
|
|
||||||
caret.range.min = p;
|
|
||||||
caret.ifront = 0;
|
|
||||||
} else if (p >= caret.range.max) {
|
|
||||||
caret.range.max = p;
|
|
||||||
caret.ifront = 1;
|
|
||||||
}
|
|
||||||
} else if (event.clicks >= 2 && InBounds({caret.range.min - 1, caret.range.max + 1}, p)) {
|
|
||||||
Range range = EncloseWord(active.buffer, p);
|
|
||||||
if (event.clicks >= 3) range = EncloseLoadWord(active.buffer, p);
|
|
||||||
caret = MakeCaret(range.max, range.min);
|
|
||||||
} else {
|
|
||||||
caret = MakeCaret(p);
|
|
||||||
}
|
|
||||||
MergeCarets(active.view);
|
|
||||||
DocumentRangeAnchor = caret.range;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out scrollbar click
|
|
||||||
// :ScrollbarImprovement
|
|
||||||
// @todo: it generally works ok but it moves the scrollbar a bit on click
|
|
||||||
// when mouse is not even moving
|
|
||||||
For(order) {
|
|
||||||
Window *window = Windows[it].o;
|
|
||||||
if (!window->visible) continue;
|
|
||||||
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
|
|
||||||
if (mouse_in_scrollbar) {
|
|
||||||
ScrollbarSelected = window->id;
|
|
||||||
|
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
Vec2 mouse_vec2 = MouseVec2();
|
|
||||||
Scroller s = ComputeScrollerRect(window);
|
|
||||||
double size_y = (double)GetSize(window->scrollbar_rect).y;
|
|
||||||
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
|
||||||
if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) {
|
|
||||||
view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
|
|
||||||
window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
|
|
||||||
} else {
|
|
||||||
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
|
||||||
}
|
|
||||||
run_window_command = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_P)) {
|
|
||||||
Command_ListBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CtrlShift(SDLK_BACKSLASH)) {
|
|
||||||
AddRowWindow();
|
|
||||||
} else if (Ctrl(SDLK_BACKSLASH)) {
|
|
||||||
AddColumnWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_0)) {
|
|
||||||
ToggleVisibility(DebugWindowID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Press(SDLK_F5)) {
|
|
||||||
AppIsRunning = false;
|
|
||||||
run_window_command = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Press(SDLK_F11)) {
|
|
||||||
ToggleFullscreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_1)) {
|
|
||||||
Window *window = GetLayoutWindow(0);
|
|
||||||
if (window) ActiveWindow = window->id;
|
|
||||||
run_window_command = false;
|
|
||||||
}
|
|
||||||
if (Ctrl(SDLK_2)) {
|
|
||||||
Window *window = GetLayoutWindow(1);
|
|
||||||
if (window) ActiveWindow = window->id;
|
|
||||||
run_window_command = false;
|
|
||||||
}
|
|
||||||
if (Ctrl(SDLK_3)) {
|
|
||||||
Window *window = GetLayoutWindow(2);
|
|
||||||
if (window) ActiveWindow = window->id;
|
|
||||||
run_window_command = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return run_window_command;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Command_ReplaceWithoutMovingCarets(View *view, Range range, String16 string) {
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
Array<Caret> caret_copy = Copy(GetSystemAllocator(), view->carets);
|
|
||||||
defer {
|
|
||||||
Dealloc(&view->carets);
|
|
||||||
view->carets = caret_copy;
|
|
||||||
};
|
|
||||||
|
|
||||||
Scratch scratch;
|
|
||||||
Command_SelectRangeOneCursor(view, range);
|
|
||||||
Array<Edit> edits = Command_ReplaceEx(scratch, view, string);
|
|
||||||
AdjustCarets(edits, &caret_copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Command_Append(View *view, String16 string, bool scroll_to_end_if_cursor_on_last_line) {
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
|
|
||||||
bool scroll_to_end = false;
|
|
||||||
if (scroll_to_end_if_cursor_on_last_line) {
|
|
||||||
Int line = PosToLine(buffer, GetFront(view->carets[0]));
|
|
||||||
if (line == buffer->line_starts.len - 1) scroll_to_end = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array<Caret> caret_copy = {};
|
|
||||||
if (!scroll_to_end) caret_copy = Copy(GetSystemAllocator(), view->carets);
|
|
||||||
defer {
|
|
||||||
if (!scroll_to_end) {
|
|
||||||
Dealloc(&view->carets);
|
|
||||||
view->carets = caret_copy;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Command_SelectRangeOneCursor(view, GetEndAsRange(buffer));
|
|
||||||
Command_Replace(view, string);
|
|
||||||
Command_Replace(view, L"\n");
|
|
||||||
|
|
||||||
if (scroll_to_end) {
|
|
||||||
view->carets[0] = MakeCaret(GetEndAsRange(buffer).min);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Command_Append(View *view, String string, bool scroll_to_end_if_cursor_on_last_line) {
|
|
||||||
Scratch scratch;
|
|
||||||
String16 string16 = ToString16(scratch, string);
|
|
||||||
Command_Append(view, string16, scroll_to_end_if_cursor_on_last_line);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReportErrorf(const char *fmt, ...) {
|
|
||||||
Scratch scratch;
|
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
|
||||||
View *view = GetView(NullViewID);
|
|
||||||
Command_Append(view, string, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReportConsolef(const char *fmt, ...) {
|
|
||||||
Scratch scratch;
|
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
|
||||||
View *view = GetView(NullViewID);
|
|
||||||
Command_Append(view, string, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReportWarningf(const char *fmt, ...) {
|
|
||||||
Scratch scratch;
|
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
|
||||||
View *null_view = GetView(NullViewID);
|
|
||||||
Command_Append(null_view, string, true);
|
|
||||||
|
|
||||||
Window *window = GetWindowWithView(null_view->id);
|
|
||||||
if (!window) window = GetActiveMainSet().window;
|
|
||||||
CheckpointBeforeGoto(window);
|
|
||||||
window->active_view = null_view->id;
|
|
||||||
ActiveWindow = window->id;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,79 @@
|
|||||||
|
|
||||||
|
void Command_ReplaceWithoutMovingCarets(View *view, Range range, String16 string) {
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
Array<Caret> caret_copy = Copy(GetSystemAllocator(), view->carets);
|
||||||
|
defer {
|
||||||
|
Dealloc(&view->carets);
|
||||||
|
view->carets = caret_copy;
|
||||||
|
};
|
||||||
|
|
||||||
|
Scratch scratch;
|
||||||
|
Command_SelectRangeOneCursor(view, range);
|
||||||
|
Array<Edit> edits = Command_ReplaceEx(scratch, view, string);
|
||||||
|
AdjustCarets(edits, &caret_copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_Append(View *view, String16 string, bool scroll_to_end_if_cursor_on_last_line) {
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
|
bool scroll_to_end = false;
|
||||||
|
if (scroll_to_end_if_cursor_on_last_line) {
|
||||||
|
Int line = PosToLine(buffer, GetFront(view->carets[0]));
|
||||||
|
if (line == buffer->line_starts.len - 1) scroll_to_end = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array<Caret> caret_copy = {};
|
||||||
|
if (!scroll_to_end) caret_copy = Copy(GetSystemAllocator(), view->carets);
|
||||||
|
defer {
|
||||||
|
if (!scroll_to_end) {
|
||||||
|
Dealloc(&view->carets);
|
||||||
|
view->carets = caret_copy;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Command_SelectRangeOneCursor(view, GetEndAsRange(buffer));
|
||||||
|
Command_Replace(view, string);
|
||||||
|
Command_Replace(view, L"\n");
|
||||||
|
|
||||||
|
if (scroll_to_end) {
|
||||||
|
view->carets[0] = MakeCaret(GetEndAsRange(buffer).min);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_Append(View *view, String string, bool scroll_to_end_if_cursor_on_last_line) {
|
||||||
|
Scratch scratch;
|
||||||
|
String16 string16 = ToString16(scratch, string);
|
||||||
|
Command_Append(view, string16, scroll_to_end_if_cursor_on_last_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportErrorf(const char *fmt, ...) {
|
||||||
|
Scratch scratch;
|
||||||
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
||||||
|
View *view = GetView(NullViewID);
|
||||||
|
Command_Append(view, string, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportConsolef(const char *fmt, ...) {
|
||||||
|
Scratch scratch;
|
||||||
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
|
View *view = GetView(NullViewID);
|
||||||
|
Command_Append(view, string, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportWarningf(const char *fmt, ...) {
|
||||||
|
Scratch scratch;
|
||||||
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
|
View *null_view = GetView(NullViewID);
|
||||||
|
Command_Append(null_view, string, true);
|
||||||
|
|
||||||
|
Window *window = GetWindowWithView(null_view->id);
|
||||||
|
if (!window) window = GetActiveMainSet().window;
|
||||||
|
CheckpointBeforeGoto(window);
|
||||||
|
window->active_view = null_view->id;
|
||||||
|
ActiveWindow = window->id;
|
||||||
|
}
|
||||||
|
|
||||||
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
||||||
Assert(direction == DIR_UP || direction == DIR_DOWN);
|
Assert(direction == DIR_UP || direction == DIR_DOWN);
|
||||||
BSet set = GetBSet(window);
|
BSet set = GetBSet(window);
|
||||||
@@ -505,15 +580,18 @@ void Command_CreateCursorVertical(View *_view, int direction) {
|
|||||||
MergeCarets(_view);
|
MergeCarets(_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_SelectRangeOneCursor(View *view, Range range) {
|
void Command_SelectRangeOneCursor(View *view, Caret caret) {
|
||||||
view->carets.len = 1;
|
view->carets.len = 1;
|
||||||
view->carets[0] = MakeCaret(range.min, range.max);
|
view->carets[0] = caret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_SelectRangeOneCursor(View *view, Range range) {
|
||||||
|
Command_SelectRangeOneCursor(view, MakeCaret(range.min, range.max));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_SelectEntireBuffer(View *view) {
|
void Command_SelectEntireBuffer(View *view) {
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
view->carets.len = 1;
|
Command_SelectRangeOneCursor(view, GetRange(buffer));
|
||||||
view->carets[0] = MakeCaret(0, buffer->len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge carets that overlap, this needs to be handled before any edits to
|
// Merge carets that overlap, this needs to be handled before any edits to
|
||||||
@@ -608,8 +686,7 @@ void Command_Find(View *seek_view, String16 needle, bool forward = true) {
|
|||||||
Caret caret = seek_view->carets[0];
|
Caret caret = seek_view->carets[0];
|
||||||
if (forward) caret = FindNext(seek_buffer, needle, caret);
|
if (forward) caret = FindNext(seek_buffer, needle, caret);
|
||||||
if (!forward) caret = FindPrev(seek_buffer, needle, caret);
|
if (!forward) caret = FindPrev(seek_buffer, needle, caret);
|
||||||
seek_view->carets.len = 1;
|
Command_SelectRangeOneCursor(seek_view, caret);
|
||||||
seek_view->carets[0] = caret;
|
|
||||||
|
|
||||||
IF_DEBUG(AssertRanges(seek_view->carets));
|
IF_DEBUG(AssertRanges(seek_view->carets));
|
||||||
}
|
}
|
||||||
@@ -661,176 +738,431 @@ void Command_FuzzySort(View *view, String16 needle) {
|
|||||||
|
|
||||||
Command_SelectEntireBuffer(view);
|
Command_SelectEntireBuffer(view);
|
||||||
Command_Replace(view, GetString(temp_buffer));
|
Command_Replace(view, GetString(temp_buffer));
|
||||||
|
Command_SelectRangeOneCursor(view, Rng(0));
|
||||||
view->carets.len = 1;
|
|
||||||
view->carets[0] = MakeCaret({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowCommand(Event event, Window *window, View *view) {
|
void Command_SelectTitlebarCommand(Window *window, String16 needle) {
|
||||||
ProfileFunction();
|
BSet title = GetTitleSet(window);
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
String16 buffer_string = GetString(title.buffer);
|
||||||
Int buffer_change_id = buffer->change_id;
|
ActiveWindow = title.window->id;
|
||||||
|
|
||||||
if (Ctrl(SDLK_F2)) {
|
Scratch scratch;
|
||||||
LoadBigLine(buffer);
|
String16 quoted16 = {};
|
||||||
} else if (Press(SDLK_F2)) {
|
{
|
||||||
LoadBigText(buffer);
|
String needle8 = ToString(scratch, needle);
|
||||||
|
String quoted = Format(scratch, "%.*s\")", FmtString(needle8));
|
||||||
|
quoted16 = ToString16(scratch, quoted);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Press(SDLK_ESCAPE)) {
|
int64_t index = 0;
|
||||||
if (window->deactivate_on_escape) {
|
if (Seek(buffer_string, needle, &index)) {
|
||||||
ActiveWindow = GetActiveMainSet().window->id;
|
Command_SelectRangeOneCursor(title.view, Rng(index + needle.len));
|
||||||
} else {
|
} else {
|
||||||
view->carets.len = 1;
|
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer));
|
||||||
|
Command_Replace(title.view, quoted16);
|
||||||
|
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer) - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalCommand(Event event) {
|
||||||
|
ProfileFunction();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Window cursor setting
|
||||||
|
//
|
||||||
|
Scratch scratch;
|
||||||
|
Array<Int> order = GetWindowZOrder(scratch);
|
||||||
|
{
|
||||||
|
static SDL_Cursor *SDL_MouseCursor;
|
||||||
|
if (SDL_MouseCursor) {
|
||||||
|
SDL_DestroyCursor(SDL_MouseCursor);
|
||||||
|
SDL_MouseCursor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
For(order) {
|
||||||
|
Window *window = Windows[it].o;
|
||||||
|
if (!window->visible) continue;
|
||||||
|
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
|
||||||
|
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
|
||||||
|
|
||||||
|
if (!IsDocumentSelectionValid() && (mouse_in_scrollbar || IsScrollbarSelectionValid())) {
|
||||||
|
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||||
|
SDL_SetCursor(SDL_MouseCursor);
|
||||||
|
break;
|
||||||
|
} else if (mouse_in_total || IsDocumentSelectionValid()) {
|
||||||
|
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
||||||
|
SDL_SetCursor(SDL_MouseCursor);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!SDL_MouseCursor) {
|
||||||
|
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||||
|
SDL_SetCursor(SDL_MouseCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle wheel scrolling
|
||||||
|
if (event.wheel.x || event.wheel.y) {
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
|
||||||
|
For(order) {
|
||||||
|
Window *window = Windows[it].o;
|
||||||
|
if (!window->visible) continue;
|
||||||
|
|
||||||
|
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
||||||
|
if (mouse_in_window) {
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
view->scroll.y -= (Int)(event.wheel.y * 48);
|
||||||
|
view->scroll.x += (Int)(event.wheel.x * 48);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle selected window scrollbar
|
||||||
|
// @note: the order here assumes that we won't run this code on the
|
||||||
|
// same event as the scroll was pressed
|
||||||
|
if (IsScrollbarSelectionValid() && Mouse(LEFT_UP)) {
|
||||||
|
Assert(DocumentSelected.id == -1);
|
||||||
|
ScrollbarSelected.id = -1;
|
||||||
|
} else if (IsScrollbarSelectionValid()) {
|
||||||
|
// :ScrollbarImprovement
|
||||||
|
// @todo: it generally works ok but it moves the scrollbar a bit on click
|
||||||
|
// when mouse is not even moving
|
||||||
|
Assert(DocumentSelected.id == -1);
|
||||||
|
Window *window = GetWindow(ScrollbarSelected);
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Vec2 mouse_vec2 = MouseVec2();
|
||||||
|
Scroller s = ComputeScrollerRect(window);
|
||||||
|
double size_y = (double)GetSize(window->scrollbar_rect).y;
|
||||||
|
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
||||||
|
double v = p / size_y;
|
||||||
|
v = v + (window->mouse_scroller_offset);
|
||||||
|
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DocumentSelected != ActiveWindow) {
|
||||||
|
DocumentSelected.id = -1;
|
||||||
|
} else if (IsDocumentSelectionValid() && MouseUp()) {
|
||||||
|
Assert(ScrollbarSelected.id == -1);
|
||||||
|
DocumentSelected.id = -1;
|
||||||
|
} else if (IsDocumentSelectionValid()) {
|
||||||
|
Assert(ScrollbarSelected.id == -1);
|
||||||
|
BSet selected = GetBSet(DocumentSelected);
|
||||||
|
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
// Special case for full-screen where we can have document
|
||||||
|
// aligned with monitor screen in which case mouse cursor cannot
|
||||||
|
// be smaller then 0 which means we cannot scroll
|
||||||
|
if (mouse.y == 0 && selected.window->document_rect.min.y == 0) {
|
||||||
|
float x, y;
|
||||||
|
SDL_GetGlobalMouseState(&x, &y);
|
||||||
|
if (y == 0) {
|
||||||
|
mouse.y = -10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
|
||||||
|
Caret &caret = selected.view->carets[0];
|
||||||
|
|
||||||
|
caret = SetFrontWithAnchor(caret, DocumentRangeAnchor, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set active window on click
|
||||||
|
if (MousePress()) {
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
For(order) {
|
||||||
|
Window *window = Windows[it].o;
|
||||||
|
if (!window->visible) continue;
|
||||||
|
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||||
|
if (mouse_in_document) {
|
||||||
|
ActiveWindow = window->id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.ctrl && event.shift && Mouse(RIGHT)) {
|
||||||
|
GotoForward(GetActiveMainSet().window);
|
||||||
|
} else if (event.alt && event.ctrl && Mouse(RIGHT)) {
|
||||||
|
} else if (event.ctrl && Mouse(RIGHT)) {
|
||||||
|
GotoBackward(GetActiveMainSet().window);
|
||||||
|
} else if (event.alt && Mouse(RIGHT)) {
|
||||||
|
} else if (Mouse(RIGHT)) {
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
BSet active = GetActiveSet();
|
||||||
|
bool mouse_in_document = CheckCollisionPointRec(mouse, active.window->document_rect);
|
||||||
|
if (mouse_in_document) {
|
||||||
|
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
||||||
|
Int saved_front = -1;
|
||||||
|
|
||||||
|
IterRemove(active.view->carets) {
|
||||||
|
IterRemovePrepare(active.view->carets);
|
||||||
|
if (InBounds(it.range, p)) {
|
||||||
|
String16 string = GetString(active.buffer, it.range);
|
||||||
|
SaveStringInClipboard(string);
|
||||||
|
|
||||||
|
remove_item = true;
|
||||||
|
saved_front = GetFront(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (active.view->carets.len == 0) Add(&active.view->carets, MakeCaret(saved_front));
|
||||||
|
|
||||||
|
if (saved_front == -1) {
|
||||||
|
Int line = PosToLine(active.buffer, p);
|
||||||
|
Range line_range = GetLineRangeWithoutNL(active.buffer, line);
|
||||||
|
String16 string = GetString(active.buffer, line_range);
|
||||||
|
SaveStringInClipboard(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo: maybe move some of this stuff to window command ???
|
||||||
|
// for now let's leave it because we are relaying on global state
|
||||||
|
// - maybe just do the check if active window is matching the DocumentSelected window
|
||||||
|
// - if scrollbar selected then don't invoke window command
|
||||||
|
if (event.ctrl && event.shift && Mouse(LEFT)) {
|
||||||
|
MouseExecWord(event);
|
||||||
|
} else if (event.ctrl && Mouse(LEFT)) {
|
||||||
|
MouseLoadWord(event);
|
||||||
|
} else if (Mouse(LEFT)) { // CTRL SHIFT
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
{
|
||||||
|
Assert(ScrollbarSelected.id == -1);
|
||||||
|
Assert(DocumentSelected.id == -1);
|
||||||
|
|
||||||
|
BSet active = GetActiveSet();
|
||||||
|
bool mouse_in_document = CheckCollisionPointRec(mouse, active.window->document_rect);
|
||||||
|
bool mouse_in_line_numbers = CheckCollisionPointRec(mouse, active.window->line_numbers_rect);
|
||||||
|
if (mouse_in_document || mouse_in_line_numbers) {
|
||||||
|
DocumentSelected = active.window->id;
|
||||||
|
|
||||||
|
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
||||||
|
if (event.alt) Insert(&active.view->carets, MakeCaret(p, p), 0);
|
||||||
|
if (!event.alt && !event.shift) active.view->carets.len = 1;
|
||||||
|
|
||||||
|
Caret &caret = active.view->carets[0];
|
||||||
|
if (event.shift) {
|
||||||
|
if (p <= caret.range.min) {
|
||||||
|
caret.range.min = p;
|
||||||
|
caret.ifront = 0;
|
||||||
|
} else if (p >= caret.range.max) {
|
||||||
|
caret.range.max = p;
|
||||||
|
caret.ifront = 1;
|
||||||
|
}
|
||||||
|
} else if (event.clicks >= 2 && InBounds({caret.range.min - 1, caret.range.max + 1}, p)) {
|
||||||
|
Range range = EncloseWord(active.buffer, p);
|
||||||
|
if (event.clicks >= 3) range = EncloseLoadWord(active.buffer, p);
|
||||||
|
caret = MakeCaret(range.max, range.min);
|
||||||
|
} else {
|
||||||
|
caret = MakeCaret(p);
|
||||||
|
}
|
||||||
|
MergeCarets(active.view);
|
||||||
|
DocumentRangeAnchor = caret.range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out scrollbar click
|
||||||
|
// :ScrollbarImprovement
|
||||||
|
// @todo: it generally works ok but it moves the scrollbar a bit on click
|
||||||
|
// when mouse is not even moving
|
||||||
|
For(order) {
|
||||||
|
Window *window = Windows[it].o;
|
||||||
|
if (!window->visible) continue;
|
||||||
|
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
|
||||||
|
if (mouse_in_scrollbar) {
|
||||||
|
ScrollbarSelected = window->id;
|
||||||
|
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Vec2 mouse_vec2 = MouseVec2();
|
||||||
|
Scroller s = ComputeScrollerRect(window);
|
||||||
|
double size_y = (double)GetSize(window->scrollbar_rect).y;
|
||||||
|
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
||||||
|
if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) {
|
||||||
|
view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
|
||||||
|
window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
|
||||||
|
} else {
|
||||||
|
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_P)) {
|
||||||
|
Command_ListBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CtrlShift(SDLK_BACKSLASH)) {
|
||||||
|
AddRowWindow();
|
||||||
|
} else if (Ctrl(SDLK_BACKSLASH)) {
|
||||||
|
AddColumnWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_0)) {
|
||||||
|
ToggleVisibility(DebugWindowID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Press(SDLK_F5)) {
|
||||||
|
AppIsRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Press(SDLK_F11)) {
|
||||||
|
ToggleFullscreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_1)) {
|
||||||
|
Window *window = GetLayoutWindow(0);
|
||||||
|
if (window) ActiveWindow = window->id;
|
||||||
|
}
|
||||||
|
if (Ctrl(SDLK_2)) {
|
||||||
|
Window *window = GetLayoutWindow(1);
|
||||||
|
if (window) ActiveWindow = window->id;
|
||||||
|
}
|
||||||
|
if (Ctrl(SDLK_3)) {
|
||||||
|
Window *window = GetLayoutWindow(2);
|
||||||
|
if (window) ActiveWindow = window->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
BSet active = GetActiveSet();
|
||||||
|
|
||||||
if (event.kind == EVENT_DROP_FILE) {
|
if (event.kind == EVENT_DROP_FILE) {
|
||||||
WindowOpenBufferView(window, event.text);
|
WindowOpenBufferView(active.window, event.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlAlt(SDLK_DOWN)) {
|
if (CtrlAlt(SDLK_DOWN)) {
|
||||||
Command_DuplicateLine(view, DIR_DOWN);
|
Command_DuplicateLine(active.view, DIR_DOWN);
|
||||||
} else if (AltShift(SDLK_DOWN)) {
|
} else if (AltShift(SDLK_DOWN)) {
|
||||||
Command_CreateCursorVertical(view, DIR_DOWN);
|
Command_CreateCursorVertical(active.view, DIR_DOWN);
|
||||||
} else if (CtrlShift(SDLK_DOWN)) {
|
} else if (CtrlShift(SDLK_DOWN)) {
|
||||||
Command_Move(view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Alt(SDLK_DOWN)) {
|
} else if (Alt(SDLK_DOWN)) {
|
||||||
Command_MoveLine(view, DIR_DOWN);
|
Command_MoveLine(active.view, DIR_DOWN);
|
||||||
} else if (Ctrl(SDLK_DOWN)) {
|
} else if (Ctrl(SDLK_DOWN)) {
|
||||||
Command_Move(view, DIR_DOWN, CTRL_PRESSED);
|
Command_Move(active.view, DIR_DOWN, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_DOWN)) {
|
} else if (Shift(SDLK_DOWN)) {
|
||||||
Command_Move(view, DIR_DOWN, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_DOWN, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_DOWN)) {
|
} else if (Press(SDLK_DOWN)) {
|
||||||
Command_Move(view, DIR_DOWN);
|
Command_Move(active.view, DIR_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlAlt(SDLK_UP)) {
|
if (CtrlAlt(SDLK_UP)) {
|
||||||
Command_DuplicateLine(view, DIR_UP);
|
Command_DuplicateLine(active.view, DIR_UP);
|
||||||
} else if (AltShift(SDLK_UP)) {
|
} else if (AltShift(SDLK_UP)) {
|
||||||
Command_CreateCursorVertical(view, DIR_UP);
|
Command_CreateCursorVertical(active.view, DIR_UP);
|
||||||
} else if (CtrlShift(SDLK_UP)) {
|
} else if (CtrlShift(SDLK_UP)) {
|
||||||
Command_Move(view, DIR_UP, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Alt(SDLK_UP)) {
|
} else if (Alt(SDLK_UP)) {
|
||||||
Command_MoveLine(view, DIR_UP);
|
Command_MoveLine(active.view, DIR_UP);
|
||||||
} else if (Ctrl(SDLK_UP)) {
|
} else if (Ctrl(SDLK_UP)) {
|
||||||
Command_Move(view, DIR_UP, CTRL_PRESSED);
|
Command_Move(active.view, DIR_UP, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_UP)) {
|
} else if (Shift(SDLK_UP)) {
|
||||||
Command_Move(view, DIR_UP, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_UP, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_UP)) {
|
} else if (Press(SDLK_UP)) {
|
||||||
Command_Move(view, DIR_UP);
|
Command_Move(active.view, DIR_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_LEFT)) {
|
if (CtrlShift(SDLK_LEFT)) {
|
||||||
Command_Move(view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Ctrl(SDLK_LEFT)) {
|
} else if (Ctrl(SDLK_LEFT)) {
|
||||||
Command_Move(view, DIR_LEFT, CTRL_PRESSED);
|
Command_Move(active.view, DIR_LEFT, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_LEFT)) {
|
} else if (Shift(SDLK_LEFT)) {
|
||||||
Command_Move(view, DIR_LEFT, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_LEFT, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_LEFT)) {
|
} else if (Press(SDLK_LEFT)) {
|
||||||
Command_Move(view, DIR_LEFT);
|
Command_Move(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_RIGHT)) {
|
if (CtrlShift(SDLK_RIGHT)) {
|
||||||
Command_Move(view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESSED);
|
||||||
} else if (Ctrl(SDLK_RIGHT)) {
|
} else if (Ctrl(SDLK_RIGHT)) {
|
||||||
Command_Move(view, DIR_RIGHT, CTRL_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, CTRL_PRESSED);
|
||||||
} else if (Shift(SDLK_RIGHT)) {
|
} else if (Shift(SDLK_RIGHT)) {
|
||||||
Command_Move(view, DIR_RIGHT, false, SHIFT_PRESSED);
|
Command_Move(active.view, DIR_RIGHT, false, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_RIGHT)) {
|
} else if (Press(SDLK_RIGHT)) {
|
||||||
Command_Move(view, DIR_RIGHT);
|
Command_Move(active.view, DIR_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_Z)) {
|
if (CtrlShift(SDLK_Z)) {
|
||||||
RedoEdit(buffer, &view->carets);
|
RedoEdit(active.buffer, &active.view->carets);
|
||||||
} else if (Ctrl(SDLK_Z)) {
|
} else if (Ctrl(SDLK_Z)) {
|
||||||
UndoEdit(buffer, &view->carets);
|
UndoEdit(active.buffer, &active.view->carets);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_C)) {
|
if (Ctrl(SDLK_C)) {
|
||||||
Command_Copy(view);
|
Command_Copy(active.view);
|
||||||
} else if (Ctrl(SDLK_V)) {
|
} else if (Ctrl(SDLK_V)) {
|
||||||
Command_Paste(view);
|
Command_Paste(active.view);
|
||||||
} else if (Ctrl(SDLK_X)) {
|
} else if (Ctrl(SDLK_X)) {
|
||||||
PreBeginEdit_SaveCaretHistory(buffer, view->carets);
|
PreBeginEdit_SaveCaretHistory(active.buffer, active.view->carets);
|
||||||
Command_Copy(view);
|
Command_Copy(active.view);
|
||||||
Command_Replace(view, L"");
|
Command_Replace(active.view, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_A)) {
|
if (Ctrl(SDLK_A)) {
|
||||||
Command_SelectEntireBuffer(view);
|
Command_SelectEntireBuffer(active.view);
|
||||||
view->update_scroll = false;
|
active.view->update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_PAGEUP)) {
|
if (Shift(SDLK_PAGEUP)) {
|
||||||
Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED);
|
Command_MoveCursorsByPageSize(active.window, DIR_UP, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_PAGEUP)) {
|
} else if (Press(SDLK_PAGEUP)) {
|
||||||
Command_MoveCursorsByPageSize(window, DIR_UP);
|
Command_MoveCursorsByPageSize(active.window, DIR_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_PAGEDOWN)) {
|
if (Shift(SDLK_PAGEDOWN)) {
|
||||||
Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED);
|
Command_MoveCursorsByPageSize(active.window, DIR_DOWN, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_PAGEDOWN)) {
|
} else if (Press(SDLK_PAGEDOWN)) {
|
||||||
Command_MoveCursorsByPageSize(window, DIR_DOWN);
|
Command_MoveCursorsByPageSize(active.window, DIR_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_HOME)) {
|
if (Shift(SDLK_HOME)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_LEFT, SHIFT_PRESSED);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_HOME)) {
|
} else if (Press(SDLK_HOME)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_LEFT);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_END)) {
|
if (Shift(SDLK_END)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_RIGHT, SHIFT_PRESSED);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_END)) {
|
} else if (Press(SDLK_END)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_RIGHT);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_TAB)) {
|
if (Shift(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(view, SHIFT_PRESSED);
|
Command_IndentSelectedLines(active.view, SHIFT_PRESSED);
|
||||||
} else if (Press(SDLK_TAB)) {
|
} else if (Press(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(view);
|
Command_IndentSelectedLines(active.view);
|
||||||
}
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_T)) {
|
|
||||||
Int pos = view->carets[0].range.min;
|
|
||||||
Range range = EncloseScope(buffer, pos, L'{', L'}');
|
|
||||||
view->carets[0] = MakeCaret(range.max, range.min);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ctrl(SDLK_R)) {
|
|
||||||
Int pos = view->carets[0].range.min;
|
|
||||||
view->carets[0] = MakeCaret(GetWordStart(buffer, pos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_K)) {
|
if (CtrlShift(SDLK_K)) {
|
||||||
Command_KillSelectedLines(view);
|
Command_KillSelectedLines(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_BACKSPACE)) {
|
if (Ctrl(SDLK_BACKSPACE)) {
|
||||||
Command_Delete(view, DIR_LEFT, CTRL_PRESSED);
|
Command_Delete(active.view, DIR_LEFT, CTRL_PRESSED);
|
||||||
} else if (Press(SDLK_BACKSPACE)) {
|
} else if (Press(SDLK_BACKSPACE)) {
|
||||||
Command_Delete(view, DIR_LEFT);
|
Command_Delete(active.view, DIR_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_DELETE)) {
|
if (Ctrl(SDLK_DELETE)) {
|
||||||
Command_Delete(view, DIR_RIGHT, CTRL_PRESSED);
|
Command_Delete(active.view, DIR_RIGHT, CTRL_PRESSED);
|
||||||
} else if (Press(SDLK_DELETE)) {
|
} else if (Press(SDLK_DELETE)) {
|
||||||
Command_Delete(view, DIR_RIGHT);
|
Command_Delete(active.view, DIR_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.kind == EVENT_TEXT_INPUT) {
|
if (event.kind == EVENT_TEXT_INPUT) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String string = event.text;
|
String string = event.text;
|
||||||
String16 string16 = ToString16(scratch, string);
|
String16 string16 = ToString16(scratch, string);
|
||||||
Command_Replace(view, string16);
|
Command_Replace(active.view, string16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_D)) {
|
if (Ctrl(SDLK_D)) {
|
||||||
String16 string = GetString(buffer, view->carets[0].range);
|
String16 string = GetString(active.buffer, active.view->carets[0].range);
|
||||||
Caret caret = FindNext(buffer, string, view->carets[0]);
|
Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
|
||||||
Insert(&view->carets, caret, 0);
|
Insert(&active.view->carets, caret, 0);
|
||||||
MergeCarets(view);
|
MergeCarets(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_F3)) {
|
if (Shift(SDLK_F3)) {
|
||||||
@@ -838,52 +1170,38 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
String16 search_string = ToString16(scratch, main.window->search_string);
|
String16 search_string = ToString16(scratch, main.window->search_string);
|
||||||
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
||||||
main.view->carets.len = 1;
|
Command_SelectRangeOneCursor(main.view, caret);
|
||||||
main.view->carets[0] = caret;
|
|
||||||
} else if (Press(SDLK_F3)) {
|
} else if (Press(SDLK_F3)) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
String16 search_string = ToString16(scratch, main.window->search_string);
|
String16 search_string = ToString16(scratch, main.window->search_string);
|
||||||
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
||||||
main.view->carets.len = 1;
|
Command_SelectRangeOneCursor(main.view, caret);
|
||||||
main.view->carets[0] = caret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift(SDLK_F4)) {
|
if (Shift(SDLK_F4)) {
|
||||||
Command_GotoNextInList(window, -1);
|
Command_GotoNextInList(active.window, -1);
|
||||||
} else if (Press(SDLK_F4)) {
|
} else if (Press(SDLK_F4)) {
|
||||||
Command_GotoNextInList(window, 1);
|
Command_GotoNextInList(active.window, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_RETURN)) {
|
if (CtrlShift(SDLK_RETURN)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_LEFT);
|
Command_MoveCursorsToSide(active.view, DIR_LEFT);
|
||||||
Command_IdentedNewLine(view);
|
Command_IdentedNewLine(active.view);
|
||||||
Command_Move(view, DIR_UP);
|
Command_Move(active.view, DIR_UP);
|
||||||
} else if (Ctrl(SDLK_RETURN)) {
|
} else if (Ctrl(SDLK_RETURN)) {
|
||||||
Command_MoveCursorsToSide(view, DIR_RIGHT);
|
Command_MoveCursorsToSide(active.view, DIR_RIGHT);
|
||||||
Command_IdentedNewLine(view);
|
Command_IdentedNewLine(active.view);
|
||||||
} else if (Press(SDLK_RETURN)) {
|
} else if (Press(SDLK_RETURN)) {
|
||||||
Command_IdentedNewLine(view);
|
Command_IdentedNewLine(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_F)) {
|
if (Ctrl(SDLK_F)) {
|
||||||
BSet title = GetTitleSet(window);
|
Command_SelectTitlebarCommand(active.window, L"#Search(\"");
|
||||||
String16 buffer_string = GetString(title.buffer);
|
|
||||||
ActiveWindow = title.window->id;
|
|
||||||
|
|
||||||
int64_t index = 0;
|
|
||||||
String16 needle = L"#Search(";
|
|
||||||
if (Seek(buffer_string, needle, &index)) {
|
|
||||||
Command_SelectRangeOneCursor(title.view, Rng(index + needle.len + 1));
|
|
||||||
} else {
|
|
||||||
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer));
|
|
||||||
Command_Replace(title.view, L" #Search(\"\")");
|
|
||||||
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer) - 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_S)) {
|
if (Ctrl(SDLK_S)) {
|
||||||
SaveBuffer(view);
|
SaveBuffer(active.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_PERIOD)) {
|
if (Ctrl(SDLK_PERIOD)) {
|
||||||
@@ -894,7 +1212,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
|
|
||||||
if (CtrlShift(SDLK_G)) {
|
if (CtrlShift(SDLK_G)) {
|
||||||
} else if (Ctrl(SDLK_G)) {
|
} else if (Ctrl(SDLK_G)) {
|
||||||
ActiveWindow = GetTitleSet(window).window->id;
|
Command_SelectTitlebarCommand(active.window, L"#FuzzySort(\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_W)) {
|
if (CtrlShift(SDLK_W)) {
|
||||||
@@ -904,23 +1222,32 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_Q)) {
|
if (CtrlShift(SDLK_Q)) {
|
||||||
Caret caret = view->carets[0];
|
Caret caret = active.view->carets[0];
|
||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) range = EncloseExecWord(buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseExecWord(active.buffer, GetFront(caret));
|
||||||
String16 string = GetString(buffer, range);
|
String16 string = GetString(active.buffer, range);
|
||||||
|
|
||||||
Command_EvalLua(view, string);
|
Command_EvalLua(active.view, string);
|
||||||
} else if (Ctrl(SDLK_Q)) {
|
} else if (Ctrl(SDLK_Q)) {
|
||||||
Caret caret = view->carets[0];
|
Caret caret = active.view->carets[0];
|
||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) range = EncloseLoadWord(buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||||
String16 string = GetString(buffer, range);
|
String16 string = GetString(active.buffer, range);
|
||||||
|
|
||||||
window->active_goto_list = view->id;
|
active.window->active_goto_list = active.view->id;
|
||||||
Open(string);
|
Open(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_DEBUG(AssertRanges(view->carets));
|
if (Press(SDLK_ESCAPE)) {
|
||||||
|
if (active.window->deactivate_on_escape) {
|
||||||
|
ActiveWindow = GetActiveMainSet().window->id;
|
||||||
|
} else {
|
||||||
|
active.view->carets.len = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MergeCarets(active.view);
|
||||||
|
IF_DEBUG(AssertRanges(active.view->carets));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateScroll(Window *window, bool update_caret_scrolling) {
|
void UpdateScroll(Window *window, bool update_caret_scrolling) {
|
||||||
|
|||||||
@@ -157,12 +157,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleEvent(Event event) {
|
void HandleEvent(Event event) {
|
||||||
bool run_window_command = GlobalCommand(event);
|
GlobalCommand(event);
|
||||||
if (run_window_command) {
|
|
||||||
BSet active = GetActiveSet();
|
|
||||||
WindowCommand(event, active.window, active.view);
|
|
||||||
MergeCarets(active.view);
|
|
||||||
}
|
|
||||||
For(Windows) if (it.o->is_title_bar) ReplaceTitleBarData(it.o);
|
For(Windows) if (it.o->is_title_bar) ReplaceTitleBarData(it.o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
if (string_to_replace != string) {
|
if (string_to_replace != string) {
|
||||||
Command_SelectRangeOneCursor(title.view, replace_range);
|
Command_SelectRangeOneCursor(title.view, replace_range);
|
||||||
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, string);
|
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, string);
|
||||||
Command_SelectRangeOneCursor(title.view, {});
|
Command_SelectRangeOneCursor(title.view, Rng(0));
|
||||||
AdjustCarets(edits, &caret_copy);
|
AdjustCarets(edits, &caret_copy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
- OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own
|
- OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own
|
||||||
|
|
||||||
- ctrl + f - should find Search and select content or add Search
|
|
||||||
- some split selection commands
|
- some split selection commands
|
||||||
- assign commands or lua functions to F1-F8 keys
|
- assign commands or lua functions to F1-F8 keys
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user