diff options
author | HolonProduction <holonproduction@gmail.com> | 2023-12-05 20:57:41 +0100 |
---|---|---|
committer | HolonProduction <holonproduction@gmail.com> | 2024-02-05 20:30:53 +0100 |
commit | da6bacbc4a8802b3d87bb5cec6292dc1a3c23c68 (patch) | |
tree | ed1075dd6f814578ab419d437010cf8bccd67d76 | |
parent | d3352813ea44447bfbf135efdec23acc4d1d3f89 (diff) | |
download | redot-engine-da6bacbc4a8802b3d87bb5cec6292dc1a3c23c68.tar.gz |
Allow dragging selection when selecting whole words in `LineEdit`
-rw-r--r-- | scene/gui/line_edit.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index a6109a3925..1c5472beec 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -331,6 +331,8 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) { selection.begin = words[i]; selection.end = words[i + 1]; selection.double_click = true; + selection.creating = true; + selection.start_column = caret_column; set_caret_column(selection.end); break; } @@ -405,6 +407,27 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) { if (selection.creating) { set_caret_at_pixel_pos(m->get_position().x); selection_fill_at_caret(); + + if (selection.double_click) { + // Expand selection to whole words. + + PackedInt32Array words = TS->shaped_text_get_word_breaks(text_rid); + for (int i = 0; i < words.size(); i = i + 2) { + if ((words[i] < selection.begin && words[i + 1] > selection.begin) || (i == words.size() - 2 && selection.begin == words[i + 1])) { + selection.begin = words[i]; + } + if ((words[i] < selection.end && words[i + 1] > selection.end) || (i == words.size() - 2 && selection.end == words[i + 1])) { + selection.end = words[i + 1]; + selection.enabled = true; + break; + } + } + if (caret_column < selection.start_column) { + set_caret_column(selection.begin); + } else { + set_caret_column(selection.end); + } + } } } |