Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cursor behavior for multiselect in Tree while holding CTRL #71024

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,15 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
}

if (editor_selection->is_selected(n)) {
item->select(0);
if (!item->is_selected(0)) {
item->select(0);
}
} else {
item->deselect(0);
if (item->is_selected(0)) {
TreeItem *previous_cursor_item = tree->get_selected();
item->deselect(0);
previous_cursor_item->set_as_cursor(0);
}
}

TreeItem *c = item->get_first_child();
Expand Down
47 changes: 21 additions & 26 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2868,21 +2868,17 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
return -1;
}

if (select_mode == SELECT_MULTI && p_mod->is_command_or_control_pressed() && c.selectable) {
if (!c.selected || p_button == MouseButton::RIGHT) {
p_item->select(col);
emit_signal(SNAME("multi_selected"), p_item, col, true);
emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);

//p_item->selected_signal.call(col);
if (c.selectable) {
if (select_mode == SELECT_MULTI && p_mod->is_command_or_control_pressed()) {
if (c.selected && p_button == MouseButton::LEFT) {
p_item->deselect(col);
emit_signal(SNAME("multi_selected"), p_item, col, false);
} else {
p_item->select(col);
emit_signal(SNAME("multi_selected"), p_item, col, true);
emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);
}
} else {
p_item->deselect(col);
emit_signal(SNAME("multi_selected"), p_item, col, false);
//p_item->deselected_signal.call(col);
}

} else {
if (c.selectable) {
Copy link
Contributor Author

@marzecdawid marzecdawid Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is only a small code readability improvement.

if (select_mode == SELECT_MULTI && p_mod->is_shift_pressed() && selected_item && selected_item != p_item) {
bool inrange = false;

Expand All @@ -2902,12 +2898,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);
}
}

/*
if (!c.selected && select_mode==SELECT_MULTI) {
emit_signal(SNAME("multi_selected"),p_item,col,true);
}
*/
queue_redraw();
}
}
Expand Down Expand Up @@ -4400,21 +4390,26 @@ void Tree::item_selected(int p_column, TreeItem *p_item) {
//emit_signal(SNAME("multi_selected"),p_item,p_column,true); - NO this is for TreeItem::select

selected_col = p_column;
if (!selected_item) {
selected_item = p_item;
}
selected_item = p_item;
} else {
select_single_item(p_item, root, p_column);
}
queue_redraw();
}

void Tree::item_deselected(int p_column, TreeItem *p_item) {
if (selected_item == p_item) {
if (select_mode == SELECT_SINGLE && selected_item == p_item && selected_col == p_column) {
selected_item = nullptr;

if (selected_col == p_column) {
selected_col = -1;
} else {
if (select_mode == SELECT_ROW && selected_item == p_item) {
selected_item = nullptr;
selected_col = -1;
} else {
if (select_mode == SELECT_MULTI) {
selected_item = p_item;
selected_col = p_column;
Comment on lines +4410 to +4411
Copy link
Contributor

@lufog lufog Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If change this to:

selected_item = nullptr;
selected_col = -1;

This will fix the problem, but the frame of the deselected element

image

will break.

}
}
}

Expand Down