]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.tools.listener.history: only add a history entry if it does not match the most...
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Sep 2011 14:57:51 +0000 (07:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Sep 2011 14:57:51 +0000 (07:57 -0700)
basis/ui/tools/listener/history/history-tests.factor
basis/ui/tools/listener/history/history.factor

index 068673889a515076f37b6fe00699cc332762c4ef..331437c4721f21ac7dab37c08f997200dc25e50e 100644 (file)
@@ -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
index dae9e26dc8df7bdbfb2c28096721556a67d5b0c0..5a22021e90a41c35e0a382c06f7fa14989a63027 100644 (file)
@@ -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