diff --git a/build_file.cpp b/build_file.cpp index 1cfb315..0ce3c63 100644 --- a/build_file.cpp +++ b/build_file.cpp @@ -374,6 +374,7 @@ void GenerateConfig() { Array colors = {}; colors.add({"Text", "GruvboxDark0Hard"}); + colors.add({"TextUnderline", "GruvboxDark0Hard"}); colors.add({"Background", "GruvboxLight0Hard"}); colors.add({"InactiveWindow", "0x0000000F"}); colors.add({"TextLineNumbers", "GruvboxDark4"}); diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 881bb20..6ec74d4 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -86,7 +86,7 @@ Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) { } Int MoveOnWhitespaceBoundaryBackward(Buffer &buffer, Int pos) { - pos = Clamp(pos - 1, (Int)0, buffer.len); + pos = Clamp(pos, (Int)0, buffer.len); bool standing_on_whitespace = IsWhitespace(buffer.str[pos]); bool standing_on_symbol = IsSymbol(buffer.str[pos]); bool standing_on_word = !standing_on_whitespace && !standing_on_symbol; diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 7d6a494..2bb1500 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -621,7 +621,7 @@ void WindowCommand(Event event, Window *window, View *view) { *c = ChangeFront(*c, p); } else if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) { Caret *c = &view->carets[0]; - if (InBounds({c->range.min, c->range.max + 1}, p)) { + if (InBounds({c->range.min - 1, c->range.max + 1}, p)) { c->range = EncloseWord(*buffer, p); view->selection_anchor = c->range; } else { diff --git a/src/text_editor/generated.cpp b/src/text_editor/generated.cpp index f7d8cef..91bbdeb 100644 --- a/src/text_editor/generated.cpp +++ b/src/text_editor/generated.cpp @@ -38,6 +38,7 @@ local GruvboxFadedAqua = 0x427b58ff local GruvboxFadedOrange = 0xaf3a03ff Color = {} Color.Text = GruvboxDark0Hard +Color.TextUnderline = GruvboxDark0Hard Color.Background = GruvboxLight0Hard Color.InactiveWindow = 0x0000000F Color.TextLineNumbers = GruvboxDark4 @@ -197,6 +198,7 @@ end )=="; void ReloadStyle() { ColorText = GetColor("Text", ColorText); + ColorTextUnderline = GetColor("TextUnderline", ColorTextUnderline); ColorBackground = GetColor("Background", ColorBackground); ColorInactiveWindow = GetColor("InactiveWindow", ColorInactiveWindow); ColorTextLineNumbers = GetColor("TextLineNumbers", ColorTextLineNumbers); diff --git a/src/text_editor/generated_variables.cpp b/src/text_editor/generated_variables.cpp index 7a837ad..3af8c8d 100644 --- a/src/text_editor/generated_variables.cpp +++ b/src/text_editor/generated_variables.cpp @@ -36,6 +36,7 @@ Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff}; Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff}; Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff}; Color ColorText = GruvboxDark0Hard; +Color ColorTextUnderline = GruvboxDark0Hard; Color ColorBackground = GruvboxLight0Hard; Color ColorInactiveWindow = {0x00, 0x00, 0x00, 0x0F}; Color ColorTextLineNumbers = GruvboxDark4; diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index fec7f2e..584ece4 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -4,7 +4,6 @@ - don't trim lines with cursor or selection on it - search backwards -- underline the word which can be loaded / executed - load selected string or auto enclosed word when midclick?, ctrl + click, ctrl + e? - experiment with using multiple cursors to select command and it's input - search as a command to execute which is going to be in the title bar diff --git a/src/text_editor/window_draw.cpp b/src/text_editor/window_draw.cpp index dc73c02..9abef6d 100644 --- a/src/text_editor/window_draw.cpp +++ b/src/text_editor/window_draw.cpp @@ -167,6 +167,26 @@ void DrawWindow(Window *window) { } } + { + Caret caret = view->carets[0]; + if (GetSize(caret.range) == 0) { + Int pos = caret.range.min; + if (pos < buffer->len && !IsWhitespace(buffer->str[pos])) { + Range range = EncloseWord(*buffer, pos); + + XY xy_min = PosToXY(*buffer, range.min); + XY xy_max = PosToXY(*buffer, range.max); + + Vec2I min = {xy_min.col * FontCharSpacing, (xy_min.line + 1) * FontLineSpacing - 2}; + Vec2I max = {xy_max.col * FontCharSpacing, (xy_max.line + 1) * FontLineSpacing}; + Rect2I rect = {min, max}; + rect -= view->scroll; + rect += window->document_rect.min; + DrawRect(rect, ColorTextUnderline); + } + } + } + if (window->fuzzy_search) { Caret it = view->carets[0]; Int front = GetFront(it);