Skip to content

Commit

Permalink
REPL undo: fix edit_kill_region and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Sep 7, 2017
1 parent 5f708e8 commit 34df23e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,14 @@ function edit_copy_region(s::MIState)
end

function edit_kill_region(s::MIState)
push_kill!(s, edit_splice!(s)) || return :ignore
push_undo(s)
refresh_line(s)
:edit_kill_region
if push_kill!(s, edit_splice!(s))
refresh_line(s)
:edit_kill_region
else
pop_undo(s)
:ignore
end
end

function edit_transpose_chars(s::MIState)
Expand Down
30 changes: 30 additions & 0 deletions test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,15 @@ end
@test edit!(LineEdit.edit_clear) == ""
@test edit!(edit_undo!) == "one two three"

@test edit!(LineEdit.edit_insert_newline) == "one two three\n"
@test edit!(edit_undo!) == "one two three"

LineEdit.edit_move_left(s)
LineEdit.edit_move_left(s)
@test edit!(LineEdit.edit_transpose_chars) == "one two there"
@test edit!(edit_undo!) == "one two three"
@test edit!(LineEdit.edit_transpose_words) == "one three two"
@test edit!(edit_undo!) == "one two three"

LineEdit.move_line_start(s)
@test edit!(LineEdit.edit_kill_line) == ""
Expand All @@ -661,6 +666,15 @@ end
@test edit!(edit_undo!) == ""
@test edit!(edit_undo!) == "one two three"

LineEdit.setmark(s)
LineEdit.edit_move_word_right(s)
@test edit!(LineEdit.edit_kill_region) == " two three"
@test edit!(LineEdit.edit_yank) == "one two three"
@test edit!(LineEdit.edit_yank_pop) == "one two three two three"
@test edit!(edit_undo!) == "one two three"
@test edit!(edit_undo!) == " two three"
@test edit!(edit_undo!) == "one two three"

LineEdit.move_line_end(s)
LineEdit.edit_backspace(s)
LineEdit.edit_backspace(s)
Expand Down Expand Up @@ -692,6 +706,22 @@ end
@test edit!(edit_undo!) == "one three"
@test edit!(edit_undo!) == "one two three"

LineEdit.move_line_start(s)
@test edit!(LineEdit.edit_upper_case) == "ONE two three"
LineEdit.move_line_start(s)
@test edit!(LineEdit.edit_lower_case) == "one two three"
@test edit!(LineEdit.edit_title_case) == "one Two three"
@test edit!(edit_undo!) == "one two three"
@test edit!(edit_undo!) == "ONE two three"
@test edit!(edit_undo!) == "one two three"

LineEdit.move_line_end(s)
edit_insert(s, " ")
@test edit!(LineEdit.edit_tab) == "one two three "
@test edit!(edit_undo!) == "one two three "
@test edit!(edit_undo!) == "one two three"
# TODO: add tests for complete_line, which don't work directly

# pop initial insert of "one two three"
@test edit!(edit_undo!) == ""
@test edit!(edit_undo!) == "" # nothing more to undo (this "beeps")
Expand Down

0 comments on commit 34df23e

Please sign in to comment.