diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index 7af67ebe287a1..fe6813c168a13 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -1087,8 +1087,9 @@ function edit_transpose_chars(s::MIState) end function edit_transpose_chars(buf::IOBuffer) - position(buf) == 0 && return false + # Moving left but not transpoing anything is intentional, and matches Emacs's behavior eof(buf) && char_move_left(buf) + position(buf) == 0 && return false char_move_left(buf) pos = position(buf) a, b = read(buf, Char), read(buf, Char) diff --git a/stdlib/REPL/test/lineedit.jl b/stdlib/REPL/test/lineedit.jl index decad3eb07938..87028e239d5b8 100644 --- a/stdlib/REPL/test/lineedit.jl +++ b/stdlib/REPL/test/lineedit.jl @@ -375,6 +375,16 @@ let buf = IOBuffer() @test content(buf) == "βγαεδ" LineEdit.edit_transpose_chars(buf) @test content(buf) == "βγαδε" + + seek(buf, 0) + @inferred(LineEdit.edit_clear(buf)) + edit_insert(buf, "a") + LineEdit.edit_transpose_chars(buf) + @test content(buf) == "a" + seekend(buf) + LineEdit.edit_transpose_chars(buf) + @test content(buf) == "a" + @test position(buf) == 0 end @testset "edit_word_transpose" begin