Skip to content

Commit

Permalink
Made C-u remove only the beginning of the line by default, as it does…
Browse files Browse the repository at this point in the history
… in Readline
  • Loading branch information
Mon-Ouie committed Aug 31, 2012
1 parent 48c824b commit a65160a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/coolline/coolline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Coolline
Handler.new(?\C-a, &:beginning_of_line),
Handler.new(?\C-e, &:end_of_line),
Handler.new(?\C-k, &:kill_line),
Handler.new(?\C-u, &:clear_line),
Handler.new(?\C-u, &:kill_beginning_of_line),
Handler.new(?\C-f, &:forward_char),
Handler.new(?\C-b, &:backward_char),
Handler.new(?\C-d, &:kill_current_char_or_leave),
Expand Down
6 changes: 6 additions & 0 deletions lib/coolline/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def kill_line
line[pos..-1] = ""
end

# Removes everything up to the current character
def kill_beginning_of_line
line[0...pos] = ""
self.pos = 0
end

# Removes all the characters in the line
def clear_line
line.clear
Expand Down
49 changes: 49 additions & 0 deletions test/editor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
asserts(:line).equals ""
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals ""
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -142,6 +149,13 @@
asserts(:line).equals ""
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals "a lovely dragon"
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -216,6 +230,13 @@
asserts(:line).equals "foo "
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals " bar"
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -318,6 +339,13 @@
asserts(:line).equals "foo bar"
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals " baz"
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -425,6 +453,13 @@
asserts(:line).equals "a lovely dragon"
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals ""
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -537,6 +572,13 @@
asserts(:line).equals "foo bar "
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals "baz qux"
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down Expand Up @@ -649,6 +691,13 @@
asserts(:line).equals "foo bar b"
end

context "after killing the beginning of the line" do
hookup { topic.kill_beginning_of_line }

asserts(:pos).equals 0
asserts(:line).equals "az qux"
end

context "after transposing words" do
hookup { topic.transpose_words }

Expand Down

0 comments on commit a65160a

Please sign in to comment.