Skip to content

Commit

Permalink
Merge pull request #310 from VODGroup/redo
Browse files Browse the repository at this point in the history
Add redo for several actions
  • Loading branch information
akaDuality authored Nov 19, 2023
2 parents 2e2321b + ca7b26b commit 9b147a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
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 @@ open class DocumentPresenter {
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,6 +122,12 @@ open class DocumentPresenter {

publishControlChanges()
select(model)

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

@discardableResult
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()
}
}

0 comments on commit 9b147a1

Please sign in to comment.