Skip to content

Commit

Permalink
Don't error when transposing an empty buffer (#46925)
Browse files Browse the repository at this point in the history
  • Loading branch information
perryprog authored Sep 27, 2022
1 parent cda61ef commit 757f21e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ end

function edit_transpose_chars(buf::IOBuffer)
# Moving left but not transpoing anything is intentional, and matches Emacs's behavior
eof(buf) && char_move_left(buf)
eof(buf) && position(buf) !== 0 && char_move_left(buf)
position(buf) == 0 && return false
char_move_left(buf)
pos = position(buf)
Expand Down
9 changes: 9 additions & 0 deletions stdlib/REPL/test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ let buf = IOBuffer()
LineEdit.edit_transpose_chars(buf)
@test content(buf) == "βγαδε"


# Transposing a one-char buffer should behave like Emacs
seek(buf, 0)
@inferred(LineEdit.edit_clear(buf))
edit_insert(buf, "a")
Expand All @@ -385,6 +387,13 @@ let buf = IOBuffer()
LineEdit.edit_transpose_chars(buf)
@test content(buf) == "a"
@test position(buf) == 0

# Transposing an empty buffer shouldn't implode
seek(buf, 0)
LineEdit.edit_clear(buf)
LineEdit.edit_transpose_chars(buf)
@test content(buf) == ""
@test position(buf) == 0
end

@testset "edit_word_transpose" begin
Expand Down

0 comments on commit 757f21e

Please sign in to comment.