From 34df23e8abf91f82cec717494dcb5929d5124459 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Thu, 7 Sep 2017 10:00:57 +0200 Subject: [PATCH] REPL undo: fix edit_kill_region and add more tests --- base/repl/LineEdit.jl | 10 +++++++--- test/lineedit.jl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/base/repl/LineEdit.jl b/base/repl/LineEdit.jl index 1e1a8a9fcde47..95a05868bce22 100644 --- a/base/repl/LineEdit.jl +++ b/base/repl/LineEdit.jl @@ -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) diff --git a/test/lineedit.jl b/test/lineedit.jl index 8dc8d5aad2a53..e6b50cb14e402 100644 --- a/test/lineedit.jl +++ b/test/lineedit.jl @@ -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) == "" @@ -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) @@ -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")