瀏覽代碼

Spreadsheet: Do not cancel drag-select when moving over a cell corner

Fixes #4277.
Ali Mohammad Pur 4 年之前
父節點
當前提交
16b4a78072

+ 13 - 3
Userland/Applications/Spreadsheet/SpreadsheetView.cpp

@@ -83,14 +83,13 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
         ScopeGuard sheet_update_enabler { [&] { sheet.enable_updates(); } };
 
         auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Left);
-        auto rect = content_rect(index);
-        auto distance = rect.center().absolute_relative_distance_to(event.position());
-        if (distance.x() >= rect.width() / 2 - 5 && distance.y() >= rect.height() / 2 - 5) {
+        if (m_is_dragging_for_copy) {
             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.
+                auto rect = content_rect(index);
                 m_left_mousedown_position = rect.center();
             }
         } else if (!m_should_intercept_drag) {
@@ -125,6 +124,17 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
     TableView::mousemove_event(event);
 }
 
+void InfinitelyScrollableTableView::mousedown_event(GUI::MouseEvent& event)
+{
+    if (this->model()) {
+        auto index = index_at_event_position(event.position());
+        auto rect = content_rect(index);
+        auto distance = rect.center().absolute_relative_distance_to(event.position());
+        m_is_dragging_for_copy = distance.x() >= rect.width() / 2 - 5 && distance.y() >= rect.height() / 2 - 5;
+    }
+    AbstractTableView::mousedown_event(event);
+}
+
 void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
 {
     m_should_intercept_drag = false;

+ 2 - 0
Userland/Applications/Spreadsheet/SpreadsheetView.h

@@ -73,10 +73,12 @@ private:
     }
     virtual void did_scroll() override;
     virtual void mousemove_event(GUI::MouseEvent&) override;
+    virtual void mousedown_event(GUI::MouseEvent&) override;
     virtual void mouseup_event(GUI::MouseEvent&) override;
 
     bool m_should_intercept_drag { false };
     bool m_has_committed_to_dragging { false };
+    bool m_is_dragging_for_copy { false };
     GUI::ModelIndex m_starting_selection_index;
     RefPtr<Core::Timer> m_horizontal_scroll_end_timer;
     RefPtr<Core::Timer> m_vertical_scroll_end_timer;