Skip to content

Commit

Permalink
Merge pull request #7253 from mbauman/char-move-skips-newlines
Browse files Browse the repository at this point in the history
REPL: Moving left and right was skipping newlines
  • Loading branch information
Keno committed Jun 13, 2014
2 parents c3f252f + c7a5700 commit 87d40e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function edit_move_left(buf::IOBuffer)
#move to the next base UTF8 character to the left
while true
c = char_move_left(buf)
if charwidth(c) != 0 || position(buf) == 0
if charwidth(c) != 0 || c == '\n' || position(buf) == 0
break
end
end
Expand Down Expand Up @@ -374,7 +374,7 @@ function edit_move_right(buf::IOBuffer)
pos = position(buf)
nextc = read(buf,Char)
seek(buf,pos)
(charwidth(nextc) != 0) && break
(charwidth(nextc) != 0 || nextc == '\n') && break
end
return true
end
Expand Down
21 changes: 21 additions & 0 deletions test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ run_test(test3_func,IOBuffer("aab"))
@test a_bar == 2
@test b_bar == 1

## edit_move{left,right} ##
buf = IOBuffer("a\na\na\n")
seek(buf, 0)
for i = 1:6
LineEdit.edit_move_right(buf)
@test position(buf) == i
end
@test eof(buf)
for i = 5:0
LineEdit.edit_move_left(buf)
@test position(buf) == i
end

# skip unicode combining characters
buf = IOBuffer("ŷ")
seek(buf, 0)
LineEdit.edit_move_right(buf)
@test eof(buf)
LineEdit.edit_move_left(buf)
@test position(buf) == 0

## edit_move_{up,down} ##

buf = IOBuffer("type X\n a::Int\nend")
Expand Down

0 comments on commit 87d40e2

Please sign in to comment.