From cae6e299638c96282aaa7fdbbac0c3aff38c6162 Mon Sep 17 00:00:00 2001 From: Mikhail Rubanov Date: Sat, 2 Mar 2024 21:51:07 -0300 Subject: [PATCH] Translate selected frame --- Shared/Sources/Canvas/Drawing/DrawingController.swift | 7 ++++++- Shared/Sources/Canvas/Drawing/DrawingView.swift | 2 -- .../Features/Tests/CanvasAppKitTests/NewDrawingTests.swift | 1 + .../Features/Tests/CanvasAppKitTests/RoutingTests.swift | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Shared/Sources/Canvas/Drawing/DrawingController.swift b/Shared/Sources/Canvas/Drawing/DrawingController.swift index 7f1d079f..ce90ba19 100644 --- a/Shared/Sources/Canvas/Drawing/DrawingController.swift +++ b/Shared/Sources/Canvas/Drawing/DrawingController.swift @@ -179,6 +179,9 @@ public class DrawingController { if let corner = view.hud.corner(for: location) { startResizing(control: selectedControl, startLocation: location, corner: corner) return + } else if let frame = selectedControl as? ImageLayer { + startDragging(control: frame, startLocation: location) + return } } @@ -198,7 +201,9 @@ public class DrawingController { return } - if view.control(at: location) != nil { + let hasElementUnderCursor = view.control(at: location) != nil + let isFrameSelected = selectedControl is ImageLayer + if hasElementUnderCursor || isFrameSelected { pointerSubject.send(view.copyListener.isModifierActive ? .copy : .hover) } else { pointerSubject.send(nil) diff --git a/Shared/Sources/Canvas/Drawing/DrawingView.swift b/Shared/Sources/Canvas/Drawing/DrawingView.swift index 6f7f257a..99db056c 100644 --- a/Shared/Sources/Canvas/Drawing/DrawingView.swift +++ b/Shared/Sources/Canvas/Drawing/DrawingView.swift @@ -117,8 +117,6 @@ public extension DrawingView { // TODO: Refactor let viewsUnderCoordinate = drawnControls.filter({ control in control.model!.frame.contains(coordinate) - }) + frames.filter({ control in - control.model!.frame.contains(coordinate) }) switch viewsUnderCoordinate.count { diff --git a/VoiceOver Designer/Features/Tests/CanvasAppKitTests/NewDrawingTests.swift b/VoiceOver Designer/Features/Tests/CanvasAppKitTests/NewDrawingTests.swift index 97d41735..f9c09ab6 100644 --- a/VoiceOver Designer/Features/Tests/CanvasAppKitTests/NewDrawingTests.swift +++ b/VoiceOver Designer/Features/Tests/CanvasAppKitTests/NewDrawingTests.swift @@ -69,6 +69,7 @@ class NewDrawingTests: CanvasAfterDidLoadTests { // MARK: - Artboard func test_frameOnScreen_whenAddElementInsideFrame_shouldAddElementToFrame() throws { addFrame() + sut.deselect() XCTAssertNotNil(document.artboard.frames.first) sut.mouseDown(on: start10) diff --git a/VoiceOver Designer/Features/Tests/CanvasAppKitTests/RoutingTests.swift b/VoiceOver Designer/Features/Tests/CanvasAppKitTests/RoutingTests.swift index df8b20db..337231aa 100644 --- a/VoiceOver Designer/Features/Tests/CanvasAppKitTests/RoutingTests.swift +++ b/VoiceOver Designer/Features/Tests/CanvasAppKitTests/RoutingTests.swift @@ -1,6 +1,7 @@ import XCTest @testable import Canvas +@MainActor class RoutingTests: CanvasAfterDidLoadTests { func test_openSettings() async throws {