Add drag and drop to TextEdit
This commit is contained in:
parent
892a5a72cd
commit
0699941f07
4 changed files with 158 additions and 8 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue