-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from 3colorr/v1.1.3
V1.1.3
- Loading branch information
Showing
8 changed files
with
214 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// CalculateModel.swift | ||
// Mizuame | ||
// | ||
// Created by becomefoolish on 2023/10/14. | ||
// | ||
|
||
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// RedoUndo.swift | ||
// Mizuame | ||
// | ||
// Created by Nakamura Akira(3colorr) on 2023/10/15. | ||
// | ||
|
||
import Foundation | ||
|
||
class RedoUndo { | ||
private let MAX_HISTORIES: Int = 30 | ||
|
||
private var currentIndex: Int = 0 | ||
private var noteHistories: [String] = [] | ||
|
||
init(initialNote: String) { | ||
noteHistories.append(initialNote) | ||
} | ||
|
||
// Store snapshot of notes. | ||
// If user was executing redo or undo, this function is not store snapshot of note. | ||
public func snapshot(of note: String) -> Bool { | ||
|
||
if note == noteHistories[currentIndex] { | ||
return false | ||
} | ||
|
||
if noteHistories.count == MAX_HISTORIES { | ||
noteHistories.removeFirst() | ||
noteHistories.append(note) | ||
currentIndex = noteHistories.count - 1 | ||
|
||
return true | ||
} | ||
|
||
if currentIndex < noteHistories.count - 1 { | ||
noteHistories.removeSubrange((currentIndex + 1)..<noteHistories.count) | ||
noteHistories.append(note) | ||
currentIndex = noteHistories.count - 1 | ||
|
||
return true | ||
} | ||
|
||
|
||
noteHistories.append(note) | ||
currentIndex += 1 | ||
|
||
return true | ||
} | ||
|
||
// Return a next generation note. | ||
// If there is no next generation, return the current generation. | ||
public func redo() -> String { | ||
if currentIndex + 1 < noteHistories.count { | ||
currentIndex += 1 | ||
} | ||
|
||
return noteHistories[currentIndex] | ||
} | ||
|
||
// Return a previous generation note. | ||
// If there is no previous generation, return the current generation. | ||
public func undo() -> String { | ||
if currentIndex > 0 { | ||
currentIndex -= 1 | ||
} | ||
|
||
return noteHistories[currentIndex] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters