Skip to content

Commit

Permalink
Add ctrl-u to clear query
Browse files Browse the repository at this point in the history
  • Loading branch information
dlee committed Feb 26, 2014
1 parent 0058b67 commit fd93e07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions selecta
Expand Up @@ -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-?

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(/[^ ]* *$/, ""))
Expand Down
9 changes: 9 additions & 0 deletions spec/search_spec.rb
Expand Up @@ -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"],
Expand Down

0 comments on commit fd93e07

Please sign in to comment.