mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
Spreadsheet: Cut instead of copy when dragging a cell's items
Use cut instead of copy when dragging one or many cells' contents. This is more intuitive as most other spreadsheet applications handle the drag in this manner instead of as a copy operation.
This commit is contained in:
parent
8a7d2c3336
commit
2f2a705a8e
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/martinfalisse Commit: https://github.com/SerenityOS/serenity/commit/2f2a705a8e Pull-request: https://github.com/SerenityOS/serenity/pull/12280 Reviewed-by: https://github.com/alimpfard
@ -294,6 +294,10 @@ Position Sheet::offset_relative_to(const Position& base, const Position& offset,
|
||||
|
||||
void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Position> resolve_relative_to, CopyOperation copy_operation)
|
||||
{
|
||||
Vector<Position> target_cells;
|
||||
for (auto& position : from)
|
||||
target_cells.append(resolve_relative_to.has_value() ? offset_relative_to(to.first(), position, resolve_relative_to.value()) : to.first());
|
||||
|
||||
auto copy_to = [&](auto& source_position, Position target_position) {
|
||||
auto& target_cell = ensure(target_position);
|
||||
auto* source_cell = at(source_position);
|
||||
@ -305,7 +309,8 @@ void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Posi
|
||||
|
||||
target_cell.copy_from(*source_cell);
|
||||
if (copy_operation == CopyOperation::Cut)
|
||||
source_cell->set_data("");
|
||||
if (!target_cells.contains_slow(source_position))
|
||||
source_cell->set_data("");
|
||||
};
|
||||
|
||||
if (from.size() == to.size()) {
|
||||
|
@ -125,7 +125,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_is_hovering_cut_zone || m_is_dragging_for_copy)
|
||||
if (m_is_hovering_cut_zone || m_is_dragging_for_cut)
|
||||
set_override_cursor(Gfx::StandardCursor::Drag);
|
||||
else if (m_is_hovering_extend_zone)
|
||||
set_override_cursor(Gfx::StandardCursor::Crosshair);
|
||||
@ -133,7 +133,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
|
||||
set_override_cursor(Gfx::StandardCursor::Arrow);
|
||||
|
||||
auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Primary);
|
||||
if (m_is_dragging_for_copy) {
|
||||
if (m_is_dragging_for_cut) {
|
||||
m_is_dragging_for_select = false;
|
||||
if (holding_left_button) {
|
||||
m_has_committed_to_cutting = true;
|
||||
@ -176,7 +176,7 @@ void InfinitelyScrollableTableView::mousedown_event(GUI::MouseEvent& event)
|
||||
// when m_is_hovering_cut_zone as it can be the case that the user is targetting
|
||||
// a cell yet be outside of its bounding box due to the select_padding.
|
||||
if (m_is_hovering_cut_zone) {
|
||||
m_is_dragging_for_copy = true;
|
||||
m_is_dragging_for_cut = true;
|
||||
auto rect = content_rect(m_target_cell);
|
||||
GUI::MouseEvent adjusted_event = { (GUI::Event::Type)event.type(), rect.center(), event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y() };
|
||||
AbstractTableView::mousedown_event(adjusted_event);
|
||||
@ -190,7 +190,7 @@ void InfinitelyScrollableTableView::mousedown_event(GUI::MouseEvent& event)
|
||||
void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
|
||||
{
|
||||
m_is_dragging_for_select = false;
|
||||
m_is_dragging_for_copy = false;
|
||||
m_is_dragging_for_cut = false;
|
||||
m_has_committed_to_cutting = false;
|
||||
if (m_is_hovering_cut_zone) {
|
||||
auto rect = content_rect(m_target_cell);
|
||||
@ -204,7 +204,7 @@ void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
|
||||
void InfinitelyScrollableTableView::drop_event(GUI::DropEvent& event)
|
||||
{
|
||||
TableView::drop_event(event);
|
||||
m_is_dragging_for_copy = false;
|
||||
m_is_dragging_for_cut = false;
|
||||
set_override_cursor(Gfx::StandardCursor::Arrow);
|
||||
auto drop_index = index_at_event_position(event.position());
|
||||
if (selection().size() > 0) {
|
||||
@ -377,7 +377,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||
return;
|
||||
|
||||
auto first_position = source_positions.take_first();
|
||||
m_sheet->copy_cells(move(source_positions), move(target_positions), first_position);
|
||||
m_sheet->copy_cells(move(source_positions), move(target_positions), first_position, Spreadsheet::Sheet::CopyOperation::Cut);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ private:
|
||||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
|
||||
bool m_is_dragging_for_select { false };
|
||||
bool m_is_dragging_for_copy { false };
|
||||
bool m_is_dragging_for_cut { false };
|
||||
bool m_has_committed_to_cutting { false };
|
||||
bool m_is_hovering_extend_zone { false };
|
||||
bool m_is_hovering_cut_zone { false };
|
||||
|
Loading…
Reference in New Issue
Block a user