Skip to content

Don't error when transposing a single character #45420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions stdlib/REPL/test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a quick question: this probably doesn't need to have a @inferred, right? (Though I imagine it doesn't really matter.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was added to the other places as some type instabilities in the REPL was addressed.

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
Expand Down