mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Spreadsheet: On cut end select same cells in target location
When finished dragging and cutting, select the cells in the destination. E.g. if you select 5 cells and drag and paste them in a new location, select the 5 pasted cells in the destination.
This commit is contained in:
parent
10bbb01ed8
commit
e98d0dafa0
Notes:
sideshowbarker
2024-07-17 17:08:31 +09:00
Author: https://github.com/martinfalisse Commit: https://github.com/SerenityOS/serenity/commit/e98d0dafa0 Pull-request: https://github.com/SerenityOS/serenity/pull/12280 Reviewed-by: https://github.com/alimpfard
2 changed files with 33 additions and 0 deletions
|
@ -201,6 +201,38 @@ void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InfinitelyScrollableTableView::drop_event(GUI::DropEvent& event)
|
||||||
|
{
|
||||||
|
TableView::drop_event(event);
|
||||||
|
m_is_dragging_for_copy = false;
|
||||||
|
set_override_cursor(Gfx::StandardCursor::Arrow);
|
||||||
|
auto drop_index = index_at_event_position(event.position());
|
||||||
|
if (selection().size() > 0) {
|
||||||
|
// Get top left index position of previous selection
|
||||||
|
auto top_left_most_index = selection().first();
|
||||||
|
selection().for_each_index([&](auto& index) {
|
||||||
|
if (index.row() < top_left_most_index.row())
|
||||||
|
top_left_most_index = index;
|
||||||
|
else if (index.column() < top_left_most_index.column())
|
||||||
|
top_left_most_index = index;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Compare with drag location
|
||||||
|
auto x_diff = drop_index.column() - top_left_most_index.column();
|
||||||
|
auto y_diff = drop_index.row() - top_left_most_index.row();
|
||||||
|
|
||||||
|
// Set new selection
|
||||||
|
Vector<GUI::ModelIndex> new_selection;
|
||||||
|
for (auto& index : selection().indices()) {
|
||||||
|
auto new_index = model()->index(index.row() + y_diff, index.column() + x_diff);
|
||||||
|
new_selection.append(move(new_index));
|
||||||
|
}
|
||||||
|
selection().clear();
|
||||||
|
AbstractTableView::set_cursor(drop_index, SelectionUpdate::Set);
|
||||||
|
selection().add_all(new_selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SpreadsheetView::update_with_model()
|
void SpreadsheetView::update_with_model()
|
||||||
{
|
{
|
||||||
m_sheet_model->update();
|
m_sheet_model->update();
|
||||||
|
|
|
@ -76,6 +76,7 @@ private:
|
||||||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
virtual void mouseup_event(GUI::MouseEvent&) override;
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
||||||
|
virtual void drop_event(GUI::DropEvent&) override;
|
||||||
|
|
||||||
bool m_should_intercept_drag { false };
|
bool m_should_intercept_drag { false };
|
||||||
bool m_has_committed_to_dragging { false };
|
bool m_has_committed_to_dragging { false };
|
||||||
|
|
Loading…
Reference in a new issue