From cc8e049c0235f86ad5ee5c6eb2d2ad1c5daf2585 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 16 Jan 2009 15:37:31 -0600 Subject: [PATCH] Another clean up --- basis/ui/tools/listener/history/history.factor | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/basis/ui/tools/listener/history/history.factor b/basis/ui/tools/listener/history/history.factor index d318a2cb1c..909a2a2a6f 100644 --- a/basis/ui/tools/listener/history/history.factor +++ b/basis/ui/tools/listener/history/history.factor @@ -9,11 +9,17 @@ TUPLE: history document elements index ; : ( document -- history ) V{ } clone 0 history boa ; +: history-add ( history -- input ) + dup elements>> length 1+ >>index + [ document>> doc-string [ ] [ empty? ] bi ] keep + '[ [ _ elements>> push ] keep ] unless ; + > doc-string [ ] [ empty? ] bi ] keep - '[ [ _ [ index>> ] [ elements>> ] bi set-nth ] keep ] unless ; +: save-history ( history -- ) + [ document>> doc-string ] keep + '[ _ [ index>> ] [ elements>> ] bi set-nth ] + unless-empty ; : update-document ( history -- ) [ [ index>> ] [ elements>> ] bi nth string>> ] @@ -27,7 +33,7 @@ TUPLE: history document elements index ; : history-recall ( history i -- ) [ [ elements>> empty? ] keep ] dip '[ _ - [ save-history drop ] + [ save-history ] [ _ change-history-index ] [ update-document ] tri @@ -35,10 +41,6 @@ TUPLE: history document elements index ; PRIVATE> -: history-add ( history -- input ) - dup elements>> length 1+ >>index - save-history ; - : history-recall-previous ( history -- ) -1 history-recall ;