Skip to content

Commit

Permalink
REPL: fix newline indentation when point before 1st non-space (#23402)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet authored Aug 24, 2017
1 parent 5a002bf commit 2767355
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ function edit_insert_newline(s::PromptState, align=-1)
buf = buffer(s)
if align < 0
beg = beginofline(buf)
align = findnext(_notspace, buf.data[beg+1:buf.size], 1) - 1
align = min(findnext(_notspace, buf.data[beg+1:buf.size], 1) - 1,
position(buf) - beg) # indentation must not increase
align < 0 && (align = buf.size-beg)
end
edit_insert(buf, '\n' * ' '^align)
Expand Down
8 changes: 8 additions & 0 deletions test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,12 @@ end
@test bufferdata(s) == "for x=1:10\n é = 1\n b = 2\n \n \n"
LineEdit.edit_insert_newline(s, 2)
@test bufferdata(s) == "for x=1:10\n é = 1\n b = 2\n \n \n\n "
# test when point before first letter of the line
for i=6:10
LineEdit.edit_clear(s)
LineEdit.edit_insert(s, "begin\n x")
seek(LineEdit.buffer(s), i)
LineEdit.edit_insert_newline(s)
@test bufferdata(s) == "begin\n" * ' '^(i-6) * "\n x"
end
end

0 comments on commit 2767355

Please sign in to comment.