From 9120062889b2ed4398024e5e6f64d75b00d2abe5 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Sat, 15 Nov 2025 18:59:58 +0300 Subject: [PATCH] GUI Textbox contents move with cursor again --- src/GUIStuff/Elements/TextBox.hpp | 8 ++++++-- src/RichText/TextBox.hpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/GUIStuff/Elements/TextBox.hpp b/src/GUIStuff/Elements/TextBox.hpp index 962e81c..93f56f6 100644 --- a/src/GUIStuff/Elements/TextBox.hpp +++ b/src/GUIStuff/Elements/TextBox.hpp @@ -73,11 +73,15 @@ template class TextBox : public Element { float yOffset = bb.height() * 0.5f; yOffset -= textbox->get_height() * 0.5f; - canvas->translate(bb.min.x() + 2.0f, bb.min.y() + yOffset); RichText::TextBox::PaintOpts paintOpts; - if(selection.selected) + if(selection.selected) { paintOpts.cursor = *cur; + SkRect cursorRect = textbox->get_cursor_rect(cur->pos); + canvas->translate(bb.min.x() - std::max(cursorRect.fRight - bb.width(), -2.0f), bb.min.y() + yOffset); + } + else + canvas->translate(bb.min.x() + 2.0f, bb.min.y() + yOffset); paintOpts.cursorColor = {io.theme->fillColor1.fR, io.theme->fillColor1.fG, io.theme->fillColor1.fB}; skia::textlayout::TextStyle tStyle; diff --git a/src/RichText/TextBox.hpp b/src/RichText/TextBox.hpp index 80405d8..368f6bb 100644 --- a/src/RichText/TextBox.hpp +++ b/src/RichText/TextBox.hpp @@ -144,6 +144,7 @@ class TextBox { void process_text_input(Cursor& cur, const std::string& in, const std::optional& inputModMap = std::nullopt); void process_rich_text_input(Cursor& cur, const TextData& richText); + SkRect get_cursor_rect(TextPosition pos); private: std::pair get_start_end_text_pos(TextPosition p1, TextPosition p2); std::pair get_start_end_paragraph_pos(size_t p1, size_t p2); @@ -157,7 +158,6 @@ class TextBox { void rects_between_text_positions_func(TextPosition p1, TextPosition p2, std::function f); - SkRect get_cursor_rect(TextPosition pos); TextPosition get_text_pos_closest_to_point(Vector2f point); std::shared_ptr get_last_text_style_mod_before_pos(TextPosition pos, TextStyleModifier::ModifierType modType);