From 2f2a705a8ed41e249ca2190b763ee00712a3af42 Mon Sep 17 00:00:00 2001 From: martinfalisse Date: Tue, 8 Feb 2022 15:41:09 +0100 Subject: [PATCH] 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. --- Userland/Applications/Spreadsheet/Spreadsheet.cpp | 7 ++++++- .../Applications/Spreadsheet/SpreadsheetView.cpp | 12 ++++++------ Userland/Applications/Spreadsheet/SpreadsheetView.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index 4b83270781..91538d068f 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -294,6 +294,10 @@ Position Sheet::offset_relative_to(const Position& base, const Position& offset, void Sheet::copy_cells(Vector from, Vector to, Optional resolve_relative_to, CopyOperation copy_operation) { + Vector 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 from, Vector to, Optionalset_data(""); + if (!target_cells.contains_slow(source_position)) + source_cell->set_data(""); }; if (from.size() == to.size()) { diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp index 3e06d2b1c5..6108815506 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp @@ -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; } diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.h b/Userland/Applications/Spreadsheet/SpreadsheetView.h index 0a8e549808..95142ea601 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.h +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.h @@ -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 };