Skip to content

Commit a7533eb

Browse files
tomutaawesomekling
authored andcommitted
LibGUI: Clear selection if right-clicking item that isn't selected
If we're right-clicking on an item that isn't currently selected, clear the selection first. Fixes #3665
1 parent ad8284b commit a7533eb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Libraries/LibGUI/AbstractView.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ void AbstractView::mousedown_event(MouseEvent& event)
224224
} else if (event.button() == MouseButton::Left && m_selection.contains(index) && !m_model->drag_data_type().is_null()) {
225225
// We might be starting a drag, so don't throw away other selected items yet.
226226
m_might_drag = true;
227-
} else if (event.button() != MouseButton::Right) {
227+
} else if (event.button() == MouseButton::Right) {
228+
set_cursor(index, SelectionUpdate::ClearIfNotSelected);
229+
} else {
228230
set_cursor(index, SelectionUpdate::Set);
229231
}
230232

@@ -427,6 +429,10 @@ void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update
427429
set_selection(index);
428430
else if (selection_update == SelectionUpdate::Ctrl)
429431
toggle_selection(index);
432+
else if (selection_update == SelectionUpdate::ClearIfNotSelected) {
433+
if (!m_selection.contains(index))
434+
clear_selection();
435+
}
430436

431437
// FIXME: Support the other SelectionUpdate types
432438

Libraries/LibGUI/AbstractView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AbstractView : public ScrollableWidget {
5252
Set,
5353
Shift,
5454
Ctrl,
55+
ClearIfNotSelected
5556
};
5657

5758
virtual void move_cursor(CursorMovement, SelectionUpdate) { }

0 commit comments

Comments
 (0)