Size limit and protect edges in history

This commit is contained in:
Greg Sexton 2014-08-16 19:07:20 +01:00
parent a38aaa64c9
commit 2de6c9c403

View File

@ -273,30 +273,30 @@ with the current state and the current node at each iteration."
;;; linear history structure ;;; linear history structure
;;; TODO: size-limiting of past and future
;;; TODO: check for nils
(defun origami-h-new (present) (defun origami-h-new (present)
"Create a new history structure." "Create a new history structure."
(vector nil present nil)) (vector nil present nil))
(defun origami-h-push (h new) (defun origami-h-push (h new)
"Create a new history structure with new as the present value." "Create a new history structure with new as the present value."
(when new
(let ((past (aref h 0)) (let ((past (aref h 0))
(present (aref h 1))) (present (aref h 1)))
(vector (cons present past) new nil))) (vector (cons present (-take 19 past)) new nil))))
(defun origami-h-undo (h) (defun origami-h-undo (h)
(let ((past (aref h 0)) (let ((past (aref h 0))
(present (aref h 1)) (present (aref h 1))
(future (aref h 2))) (future (aref h 2)))
(vector (cdr past) (car past) (cons present future)))) (if (null past) h
(vector (cdr past) (car past) (cons present future)))))
(defun origami-h-redo (h) (defun origami-h-redo (h)
(let ((past (aref h 0)) (let ((past (aref h 0))
(present (aref h 1)) (present (aref h 1))
(future (aref h 2))) (future (aref h 2)))
(vector (cons present past) (car future) (cdr future)))) (if (null future) h
(vector (cons present past) (car future) (cdr future)))))
(defun origami-h-present (h) (defun origami-h-present (h)
(when h (aref h 1))) (when h (aref h 1)))