mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
Spreadsheet: Invert the drag-selection trigger
Make drag-selection the default behaviour, allowing (almost) any part of the cell to initiate a select. a small 5x5 rect at the corners of a cell can be used to initiate a drag-copy instead. Fixes #4268.
This commit is contained in:
parent
50b7122798
commit
602a830428
2 changed files with 13 additions and 5 deletions
|
@ -84,24 +84,30 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
|
||||||
if (auto model = this->model()) {
|
if (auto model = this->model()) {
|
||||||
auto index = index_at_event_position(event.position());
|
auto index = index_at_event_position(event.position());
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
return;
|
return TableView::mousemove_event(event);
|
||||||
|
|
||||||
auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Left);
|
auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Left);
|
||||||
auto rect = content_rect(index);
|
auto rect = content_rect(index);
|
||||||
auto distance = rect.center().absolute_relative_distance_to(event.position());
|
auto distance = rect.center().absolute_relative_distance_to(event.position());
|
||||||
if (distance.x() > rect.width() / 2 || distance.y() > rect.height() / 2) {
|
if (distance.x() >= rect.width() / 2 - 5 && distance.y() >= rect.height() / 2 - 5) {
|
||||||
set_override_cursor(Gfx::StandardCursor::Crosshair);
|
set_override_cursor(Gfx::StandardCursor::Crosshair);
|
||||||
|
m_should_intercept_drag = false;
|
||||||
|
if (holding_left_button) {
|
||||||
|
m_has_committed_to_dragging = true;
|
||||||
|
// Force a drag to happen by moving the mousedown position to the center of the cell.
|
||||||
|
m_left_mousedown_position = rect.center();
|
||||||
|
}
|
||||||
|
} else if (!m_should_intercept_drag) {
|
||||||
|
set_override_cursor(Gfx::StandardCursor::Arrow);
|
||||||
if (!holding_left_button) {
|
if (!holding_left_button) {
|
||||||
m_starting_selection_index = index;
|
m_starting_selection_index = index;
|
||||||
} else {
|
} else {
|
||||||
m_should_intercept_drag = true;
|
m_should_intercept_drag = true;
|
||||||
m_might_drag = false;
|
m_might_drag = false;
|
||||||
}
|
}
|
||||||
} else if (!m_should_intercept_drag) {
|
|
||||||
set_override_cursor(Gfx::StandardCursor::Arrow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holding_left_button && m_should_intercept_drag) {
|
if (holding_left_button && m_should_intercept_drag && !m_has_committed_to_dragging) {
|
||||||
if (!m_starting_selection_index.is_valid())
|
if (!m_starting_selection_index.is_valid())
|
||||||
m_starting_selection_index = index;
|
m_starting_selection_index = index;
|
||||||
|
|
||||||
|
@ -126,6 +132,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
|
||||||
void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
|
void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
m_should_intercept_drag = false;
|
m_should_intercept_drag = false;
|
||||||
|
m_has_committed_to_dragging = false;
|
||||||
TableView::mouseup_event(event);
|
TableView::mouseup_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ private:
|
||||||
virtual void mouseup_event(GUI::MouseEvent&) override;
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
||||||
|
|
||||||
bool m_should_intercept_drag { false };
|
bool m_should_intercept_drag { false };
|
||||||
|
bool m_has_committed_to_dragging { false };
|
||||||
GUI::ModelIndex m_starting_selection_index;
|
GUI::ModelIndex m_starting_selection_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue