diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-12-02 23:19:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 23:19:53 +0100 |
commit | 543462eb29245a7ffb08750ecf1c93d7522e3721 (patch) | |
tree | 5535210609831bf16ec29715c92269c8b9157a34 /scene/gui/line_edit.cpp | |
parent | d3c992429cb6a868801e855bb4e2c6eb7cfbaf5d (diff) | |
parent | 0699941f07535ff24763fd772dd4e8b8a9939e26 (diff) | |
download | redot-engine-543462eb29245a7ffb08750ecf1c93d7522e3721.tar.gz |
Merge pull request #55294 from ConteZero/text_edit_drag_and_drop
Add drag and drop to TextEdit
Diffstat (limited to 'scene/gui/line_edit.cpp')
-rw-r--r-- | scene/gui/line_edit.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 69b08fda3c..30a6f0fc9a 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -322,7 +322,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) { deselect(); selection.start_column = caret_column; selection.creating = true; - } else if (selection.enabled) { + } else if (selection.enabled && !selection.double_click) { selection.drag_attempt = true; } } @@ -588,13 +588,19 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) { if (p_data.get_type() == Variant::STRING && is_editable()) { set_caret_at_pixel_pos(p_point.x); int caret_column_tmp = caret_column; + bool is_inside_sel = selection.enabled && caret_column >= selection.begin && caret_column <= selection.end; + if (Input::get_singleton()->is_key_pressed(Key::CTRL)) { + is_inside_sel = selection.enabled && caret_column > selection.begin && caret_column < selection.end; + } if (selection.drag_attempt) { selection.drag_attempt = false; - if (caret_column < selection.begin || caret_column > selection.end) { - if (caret_column_tmp > selection.end) { - caret_column_tmp = caret_column_tmp - (selection.end - selection.begin); + if (!is_inside_sel) { + if (!Input::get_singleton()->is_key_pressed(Key::CTRL)) { + if (caret_column_tmp > selection.end) { + caret_column_tmp = caret_column_tmp - (selection.end - selection.begin); + } + selection_delete(); } - selection_delete(); set_caret_column(caret_column_tmp); insert_text_at_caret(p_data); @@ -975,7 +981,7 @@ void LineEdit::_notification(int p_what) { if (is_drag_successful()) { if (selection.drag_attempt) { selection.drag_attempt = false; - if (is_editable()) { + if (is_editable() && !Input::get_singleton()->is_key_pressed(Key::CTRL)) { selection_delete(); } else if (deselect_on_focus_loss_enabled) { deselect(); |