ui.tools.listener.history: only add a history entry if it does not match the most recent entry.
parent
7507196a98
commit
27e0071105
|
@ -1,7 +1,9 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: documents namespaces tools.test io.styles
|
||||
ui.tools.listener.history kernel ;
|
||||
|
||||
USING: accessors documents io.styles kernel namespaces
|
||||
sequences tools.test ui.tools.listener.history ;
|
||||
|
||||
IN: ui.tools.listener.history.tests
|
||||
|
||||
[ ] [ <document> "d" set ] unit-test
|
||||
|
@ -65,3 +67,9 @@ IN: ui.tools.listener.history.tests
|
|||
[ ] [ " " "d" get set-doc-string ] unit-test
|
||||
[ ] [ "h" get history-recall-previous ] unit-test
|
||||
|
||||
[ 1 ] [
|
||||
"abc" <document> [ set-doc-string ] [ <history> ] bi
|
||||
[ history-add drop ]
|
||||
[ history-add drop ]
|
||||
[ elements>> length ] tri
|
||||
] unit-test
|
||||
|
|
|
@ -9,10 +9,19 @@ TUPLE: history document elements index ;
|
|||
: <history> ( document -- history )
|
||||
V{ } clone 0 history boa ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: push-if-not-last ( elt seq -- )
|
||||
dup empty? [ push ] [
|
||||
dup last pick = [ 2drop ] [ push ] if
|
||||
] if ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: history-add ( history -- input )
|
||||
dup elements>> length 1 + >>index
|
||||
[ document>> doc-string [ <input> ] [ empty? ] bi ] keep
|
||||
'[ [ _ elements>> push ] keep ] unless ;
|
||||
'[ [ _ elements>> push-if-not-last ] keep ] unless ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
|
Loading…
Reference in New Issue