Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redo for several actions #310

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Shared/Sources/Document/Accessibility/DocumentPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@
frame: CGRect(origin: origin,
size: image.size))

add(frame, into: nil, at: document.artboard.frames.count)

document.undo?.registerUndo(withTarget: self, handler: { target in
target.remove(frame)
})
add(frame,
into: nil,
at: document.artboard.frames.count)
}

public func append(control: any ArtboardElement) {
Expand Down Expand Up @@ -124,27 +122,33 @@

publishControlChanges()
select(model)

document.undo?.registerUndo(
withTarget: self,
handler: { presenter in
presenter.remove(model)
})
}

@discardableResult
public func wrapInContainer(
_ elements: [any ArtboardElement]
) -> A11yContainer? {
controls.wrap(

Check notice on line 137 in Shared/Sources/Document/Accessibility/DocumentPresenter.swift

View check run for this annotation

Xcode Cloud / VoiceOver Designer | Test Designer | Test - macOS

Shared/Sources/Document/Accessibility/DocumentPresenter.swift#L137

'controls' is deprecated: Use `artboard`
in: A11yContainer.self,
elements.extractElements(),
label: "Container")
}

public func unwrapContainer(_ container: A11yContainer) {
controls.unwrapContainer(container)

Check notice on line 144 in Shared/Sources/Document/Accessibility/DocumentPresenter.swift

View check run for this annotation

Xcode Cloud / VoiceOver Designer | Test Designer | Test - macOS

Shared/Sources/Document/Accessibility/DocumentPresenter.swift#L144

'controls' is deprecated: Use `artboard`
}
}

#if canImport(XCTest)
extension DocumentPresenter {
public func update(elements: [A11yDescription]) {
self.controls = elements

Check notice on line 151 in Shared/Sources/Document/Accessibility/DocumentPresenter.swift

View check run for this annotation

Xcode Cloud / VoiceOver Designer | Test Designer | Test - macOS

Shared/Sources/Document/Accessibility/DocumentPresenter.swift#L151

'controls' is deprecated: Use `artboard`
}

public var firstFrameControls: [any ArtboardElement] {
Expand Down
19 changes: 18 additions & 1 deletion Shared/Tests/DocumentTests/Models/DocumentPresenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ final class DocumentPresenterTests: XCTestCase {
sut.append(control: element1)
XCTAssertEqual(sut.controlsWithoutFrame.count, 1)

sut.document.undo?.undo()
sut.undo()
XCTAssertTrue(sut.controlsWithoutFrame.isEmpty)

sut.redo()
XCTAssertFalse(sut.controlsWithoutFrame.isEmpty)
}

// MARK: - Container
Expand Down Expand Up @@ -76,6 +79,9 @@ final class DocumentPresenterTests: XCTestCase {

sut.undo()
XCTAssertEqual(container.elements.count, 2)

sut.redo()
XCTAssertEqual(container.elements.count, 1)
}

func test_container_whenRemoveContainer_shouldRemoveEverything() throws {
Expand All @@ -86,6 +92,9 @@ final class DocumentPresenterTests: XCTestCase {

sut.undo()
XCTAssertEqual(sut.controlsWithoutFrame.count, 1)

sut.redo()
XCTAssertTrue(sut.controlsWithoutFrame.isEmpty)
}

// MARK: Artboard
Expand All @@ -112,6 +121,9 @@ final class DocumentPresenterTests: XCTestCase {
sut.undo()

XCTAssertFalse(document.artboard.frames.isEmpty)

sut.redo()
XCTAssertTrue(document.artboard.frames.isEmpty)
}

// MARK: DSL
Expand All @@ -133,6 +145,7 @@ final class DocumentPresenterTests: XCTestCase {
}
}

// MARK: - Undo
extension DocumentPresenter {
func disableUndoRegistration() {
document.undo?.disableUndoRegistration()
Expand All @@ -144,4 +157,8 @@ extension DocumentPresenter {
func undo() {
document.undo?.undo()
}

func redo() {
document.undo?.redo()
}
}