diff --git a/basis/ui/tools/listener/history/history.factor b/basis/ui/tools/listener/history/history.factor index 5a22021e90..a50cf7369c 100644 --- a/basis/ui/tools/listener/history/history.factor +++ b/basis/ui/tools/listener/history/history.factor @@ -12,46 +12,48 @@ TUPLE: history document elements index ; > doc-string [ ] [ empty? ] bi ; PRIVATE> : history-add ( history -- input ) - dup elements>> length 1 + >>index - [ document>> doc-string [ ] [ empty? ] bi ] keep - '[ [ _ elements>> push-if-not-last ] keep ] unless ; + dup current-input [ nip ] [ + [ + over elements>> + [ push-if-not-last ] + [ length >>index drop ] bi + ] keep + ] if ; [ - [ [ T{ input f "" } ] dip push ] keep - (save-history) - ] [ set-nth ] if ; +: set-element ( elt history -- ) + [ index>> ] [ elements>> ] bi set-nth ; + +: get-element ( history -- elt ) + [ index>> ] [ elements>> ] bi nth ; : save-history ( history -- ) - [ document>> doc-string ] keep - '[ _ [ index>> ] [ elements>> ] bi (save-history) ] - unless-empty ; + dup current-input [ 2drop ] [ swap set-element ] if ; : update-document ( history -- ) - [ [ index>> ] [ elements>> ] bi nth string>> ] [ document>> ] bi - [ set-doc-string ] [ clear-undo drop ] 2bi ; + [ get-element string>> ] [ document>> ] bi + [ set-doc-string ] [ clear-undo ] bi ; : change-history-index ( history i -- ) over elements>> length 1 - - '[ _ + _ min 0 max ] change-index drop ; + '[ _ + 0 _ clamp ] change-index drop ; : history-recall ( history i -- ) - [ [ elements>> empty? ] keep ] dip '[ - _ - [ save-history ] - [ _ change-history-index ] - [ update-document ] - tri - ] unless ; + over elements>> empty? [ 2drop ] [ + [ drop save-history ] + [ change-history-index ] + [ drop update-document ] + 2tri + ] if ; PRIVATE>