aboutsummaryrefslogtreecommitdiff
path: root/internal/model/undo.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-29 04:03:38 -0400
committerhistoria <[not public]>2026-06-29 04:03:38 -0400
commitba34490aaed5f7c242c2b0453130fefc07d0d5d0 (patch)
treedb5818757d5080221494cead1c7e61a576d1cb65 /internal/model/undo.go
parentb1e252c996a6332d391f96624a7d6f149eb097c4 (diff)
downloadtui-ascii-mapper-main.tar.gz
restructured projectHEADmain
Diffstat (limited to 'internal/model/undo.go')
-rw-r--r--internal/model/undo.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/model/undo.go b/internal/model/undo.go
new file mode 100644
index 0000000..5b0297b
--- /dev/null
+++ b/internal/model/undo.go
@@ -0,0 +1,42 @@
+package model
+
+type UndoStack struct {
+ states []Entry
+ pos int
+}
+
+type Entry struct {
+ Target *Map
+ State *Map
+}
+
+func (u *UndoStack) Push(target *Map) {
+ keep := u.pos + 1
+ if keep > len(u.states) {
+ keep = len(u.states)
+ }
+ u.states = append(u.states[:keep], Entry{Target: target, State: target.Clone()})
+ u.pos = len(u.states) - 1
+ if len(u.states) > 100 {
+ u.states = u.states[1:]
+ u.pos--
+ }
+}
+
+func (u *UndoStack) Undo() *Entry {
+ if u.pos <= 0 {
+ return nil
+ }
+ u.pos--
+ return &u.states[u.pos]
+}
+
+func (u *UndoStack) Redo() *Entry {
+ if u.pos >= len(u.states)-1 {
+ return nil
+ }
+ u.pos++
+ return &u.states[u.pos]
+}
+
+func (u *UndoStack) Pos() int { return u.pos }