From 93e0104c1e5fad38983d2363873e101339848af2 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 24 Jul 2024 13:53:21 +0200 Subject: [PATCH] Ctrl + Enter --- src/text_editor/commands_window.cpp | 15 +++++++++------ src/text_editor/text_editor.h | 1 - 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index e44b3c8..6b9741b 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -111,7 +111,7 @@ void Command_CreateCursorVertical(View *_view, int direction) { MergeCarets(*buffer, &view.carets); } -void Command_SelectRange(View *view, Range range) { +void Command_SelectRangeOneCursor(View *view, Range range) { Buffer *buffer = GetBuffer(view->buffer_id); view->carets.len = 1; view->carets[0] = MakeCaret(range.min, range.max); @@ -336,9 +336,9 @@ void HandleActiveWindowBindings(Window *window) { if (Ctrl() && eval_result.len) { Command_SelectEntireBuffer(&view); Command_Replace(&view, eval_result); - Command_SelectRange(&view, {}); + Command_SelectRangeOneCursor(&view, {}); Command_Replace(&view, L"\n"); - Command_SelectRange(&view, {}); + Command_SelectRangeOneCursor(&view, {}); } else { { Window *window = GetWindow(GetLastActiveWindow()); @@ -348,12 +348,15 @@ void HandleActiveWindowBindings(Window *window) { } Range range = GetLineRangeWithoutNL(*buffer, 0); - Command_SelectRange(&view, range); + Command_SelectRangeOneCursor(&view, range); Command_Replace(&view, {}); } } } else { - if (Press(KEY_ENTER)) { + if (CtrlPress(KEY_ENTER)) { + Command_MoveCursorsToSide(window, DIR_RIGHT); + Command_Replace(&view, L"\n"); + } else if (Press(KEY_ENTER)) { Command_Replace(&view, L"\n"); } } @@ -540,5 +543,5 @@ void ReplaceInfobarData() { String s = Format(scratch, "line: %5lld col: %5lld name: %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name)); String16 string = ToString16(scratch, s); ReplaceText(buffer, {0, buffer->len}, string); - Command_SelectRange(view, {}); + Command_SelectRangeOneCursor(view, {}); } \ No newline at end of file diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index f4f1985..2c3db1a 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -89,7 +89,6 @@ BufferID NullBufferID = {0}; ViewID NullViewID = {0}; WindowID CommandWindowID = {0}; WindowID InfoBarWindowID = {0}; -// WindowID ExecBarWindowID = {0}; Array Buffers = {}; Array Views = {};