From 956f2319b5f1422a26fe8230027d9f83d8025569 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 5 Aug 2024 13:17:54 +0200 Subject: [PATCH] Ctrl + G --- src/basic/string16.cpp | 26 +++++++++++++++++++++ src/text_editor/commands_window.cpp | 21 +++++++++++++++++ src/text_editor/title_bar.cpp | 35 ++++++----------------------- src/text_editor/todo.txt | 4 ---- src/text_editor/window.cpp | 18 +++++++-------- 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/basic/string16.cpp b/src/basic/string16.cpp index 672444c..53d2744 100644 --- a/src/basic/string16.cpp +++ b/src/basic/string16.cpp @@ -220,3 +220,29 @@ bool StartsWith(String16 a, String16 start, unsigned ignore_case = false) { bool result = AreEqual(start, a_start, ignore_case); return result; } + +// chop this - :324 +String16 ChopNumberEx(String16 *string) { + String16 col = {}; + for (int64_t i = string->len - 1; i >= 0; i -= 1) { + if (IsDigit(string->data[i])) { + col.data = string->data + i; + col.len += 1; + } else if (string->data[i] == L':') { + break; + } else { + return {}; + } + } + *string = Chop(*string, col.len + 1); + return col; +} + +Int ChopNumber(String16 *string) { + Scratch scratch; + String16 col = ChopNumberEx(string); + if (col.len == 0) return -1; + String num_string = ToString(scratch, col); + Int result = strtoll(num_string.data, NULL, 10) - 1; + return result; +} diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index da9f7eb..c68fc4f 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -788,6 +788,27 @@ void WindowCommand(Event event, Window *window, View *view) { } } + if (Ctrl(SDLK_G)) { + Window *titlebar = window; + if (!window->is_title_bar) titlebar = GetWindow(window->title_bar_window); + View *titlebar_view = GetView(titlebar->active_view); + Buffer *titlebar_buffer = GetBuffer(titlebar_view->active_buffer); + SetActiveWindow(titlebar->id); + + String16 buffer_string = GetString(*titlebar_buffer); + if (Seek(buffer_string, L" |", &buffer_string.len)) { + buffer_string = Trim(buffer_string); + String16 col = ChopNumberEx(&buffer_string); + String16 line = ChopNumberEx(&buffer_string); + if (line.len == 0) line = col; + if (line.len) { + Int min = line.data - buffer_string.data; + titlebar_view->carets[0] = MakeCaret(min + line.len, min); + titlebar_view->update_scroll = false; + } + } + } + if (Ctrl(SDLK_Q)) { Int p = GetFront(view->carets[0]); Range enclose = EncloseLoadWord(buffer, p); diff --git a/src/text_editor/title_bar.cpp b/src/text_editor/title_bar.cpp index fef402d..aa3943c 100644 --- a/src/text_editor/title_bar.cpp +++ b/src/text_editor/title_bar.cpp @@ -61,31 +61,14 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) { buffer_string = GetString(*buffer, replace_range); buffer_string = Trim(buffer_string); - String16 col = {}; - for (int64_t i = buffer_string.len - 1; i >= 0; i -= 1) { - if (IsDigit(buffer_string.data[i])) { - col.data = buffer_string.data + i; - col.len += 1; - } else if (buffer_string.data[i] == L':') { - break; - } else { - return; - } - } - buffer_string = Chop(buffer_string, col.len + 1); + Int column = ChopNumber(&buffer_string); + if (column == -1) return; - String16 line = {}; - for (int64_t i = buffer_string.len - 1; i >= 0; i -= 1) { - if (IsDigit(buffer_string.data[i])) { - line.data = buffer_string.data + i; - line.len += 1; - } else if (buffer_string.data[i] == L':') { - break; - } else { - return; - } + Int line = ChopNumber(&buffer_string); + if (line == -1) { + line = column; + column = 0; } - buffer_string = Chop(buffer_string, line.len + 1); Window *last_window = GetWindow(window->title_bar_window); View *last_view = GetActiveView(last_window); @@ -99,11 +82,7 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) { last_buffer->name = Copy(Perm, filepath); } - String line_string = ToString(scratch, line); - String col_string = ToString(scratch, col); - Int linei = strtoll(line_string.data, NULL, 10) - 1; - Int coli = strtoll(col_string.data, NULL, 10) - 1; - Int buffer_pos = XYToPos(*last_buffer, {coli, linei}); + Int buffer_pos = XYToPos(*last_buffer, {column, line}); Caret &caret = last_view->carets[0]; if (GetFront(caret) != buffer_pos) { diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index a69383e..29d4e55 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -3,11 +3,9 @@ - ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting BUG: there is a click hang when switching windows sometimes, you click after select and it doesn't switch active window -- WE CAN'T REALLY NOW USE POINTERS DO WE !!! WE USE DYNAMIC ARRAYS!! - mouse execute - experiment with using multiple cursors to select command and it's input -- Ctrl + G should select the line number in bar - search as a command to execute which is going to be in the title bar - each buffer needs a directory even the special ones: C:\a\b\c\+errors? - open directories - resulting in buffer with dir listing and proper buffer name @@ -15,8 +13,6 @@ BUG: there is a click hang when switching windows sometimes, you click after sel - alt/ctrl + double click should select the exec or load word - clean \r\n into \n on trim and load -- baked font as fallback -- expose font and font size to config - global config and local config - load all files in a directory diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index 02cdaa6..dc73533 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -38,7 +38,7 @@ Array GetWindowZOrder(Allocator allocator) { return order; } -Window *CreateInfobar(Window *parent_window) { +Window *CreateTitlebar(Window *parent_window) { Window *window = CreateWindow(); window->draw_scrollbar = false; window->dont_save_in_active_window_history = true; @@ -74,7 +74,7 @@ void AddColumnWindow() { window->is_column = true; View *view = OpenBufferView("*scratch*"); window->active_view = view->id; - CreateInfobar(window); + CreateTitlebar(window); } void AddRowWindow() { @@ -83,7 +83,7 @@ void AddRowWindow() { View *view = OpenBufferView("*scratch*"); window->active_view = view->id; - CreateInfobar(window); + CreateTitlebar(window); Window *active_window = GetActiveWindow(); int64_t active_window_index = GetIndex(Windows, *active_window); @@ -128,7 +128,7 @@ void InitWindows() { LoadUnicode(buffer); // LoadBigTextAndBigLine(buffer, 10000000); window->active_view = view->id; - CreateInfobar(window); + CreateTitlebar(window); } { @@ -141,7 +141,7 @@ void InitWindows() { View *view = CreateView(buffer->id); window->active_view = view->id; - CreateInfobar(window); + CreateTitlebar(window); SetVisibility(window, false); ConsoleWindowID = window->id; @@ -160,7 +160,7 @@ void InitWindows() { View *view = CreateView(buffer->id); window->z = 2; window->active_view = view->id; - Window *titlebar = CreateInfobar(window); + Window *titlebar = CreateTitlebar(window); titlebar->z = 2; SetVisibility(window, false); DebugWindowID = window->id; @@ -182,7 +182,7 @@ void InitWindows() { w->active_view = v->id; w->z = 1; - Window *titlebar = CreateInfobar(w); + Window *titlebar = CreateTitlebar(w); titlebar->z = 1; SetVisibility(w, false); @@ -202,7 +202,7 @@ void InitWindows() { View *v = CreateView(b->id); w->active_view = v->id; - CreateInfobar(w); + CreateTitlebar(w); SetVisibility(w, false); SearchWindowID = w->id; @@ -223,7 +223,7 @@ void InitWindows() { View *v = CreateView(b->id); w->active_view = v->id; - Window *infobar = CreateInfobar(w); + Window *infobar = CreateTitlebar(w); infobar->z = 2; SetVisibility(w, false);