Permalink
Browse files

Merge pull request #34 from dlee/master

Add ctrl-u to clear query
  • Loading branch information...
2 parents 0058b67 + fd93e07 commit 8a2d1f3f75ad2e699c817580513795178942bd07 @garybernhardt committed Feb 26, 2014
Showing with 16 additions and 0 deletions.
  1. +7 −0 selecta
  2. +9 −0 spec/search_spec.rb
View
@@ -23,6 +23,7 @@ require "io/console"
KEY_CTRL_C = ?\C-c
KEY_CTRL_N = ?\C-n
KEY_CTRL_P = ?\C-p
+KEY_CTRL_U = ?\C-u
KEY_CTRL_W = ?\C-w
KEY_DELETE = 127.chr # Equivalent to ?\C-?
@@ -73,6 +74,7 @@ class Selecta
when KEY_CTRL_N then search.down
when KEY_CTRL_P then search.up
+ when KEY_CTRL_U then search.clear_query
when KEY_CTRL_W then search.delete_word
when KEY_DELETE then search.backspace
@@ -202,6 +204,11 @@ class Search
:query => @query[0...-1])
end
+ def clear_query
+ merge(:index => 0,
+ :query => "")
+ end
+
def delete_word
merge(:index => 0,
:query => @query.sub(/[^ ]* *$/, ""))
View
@@ -55,6 +55,15 @@
search.append_search_string(" a b").delete_word.query.should == " a "
end
+ it "clears query" do
+ search.append_search_string("").clear_query.query.should == ""
+ search.append_search_string("a").clear_query.query.should == ""
+ search.append_search_string("a ").clear_query.query.should == ""
+ search.append_search_string("a b").clear_query.query.should == ""
+ search.append_search_string("a b ").clear_query.query.should == ""
+ search.append_search_string(" a b").clear_query.query.should == ""
+ end
+
describe "matching" do
it "only returns matching choices" do
config = Configuration.from_inputs(["a", "b"],

0 comments on commit 8a2d1f3

Please sign in to comment.