Skip to content

Commit

Permalink
Include empty end lines in Text.iterLines
Browse files Browse the repository at this point in the history
FIX: Fix a bug that caused `Text.iterLines` to not return empty lines at the end
of the iterated ranges.

Closes codemirror/dev#1295
  • Loading branch information
marijnh committed Nov 10, 2023
1 parent a14b093 commit 0f61d04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,10 @@ class LineCursor implements TextIterator {

next(skip = 0) {
let {done, lineBreak, value} = this.inner.next(skip)
if (done) {
if (done && this.afterBreak) {
this.value = ""
this.afterBreak = false
} else if (done) {
this.done = true
this.value = ""
} else if (lineBreak) {
Expand Down
3 changes: 2 additions & 1 deletion test/test-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ describe("Text", () => {
ist(get(), "ab\ncde\n\n\nf\n\ng")
ist(get(1, doc.lines + 1), "ab\ncde\n\n\nf\n\ng")
ist(get(2, 3), "cde")
ist(get(1, 1), "")
ist(get(2, 3), "cde")
ist(get(1, 5), "ab\ncde\n\n")
ist(get(2, 1), "")
ist(get(3), "\n\nf\n\ng")
})
Expand Down

0 comments on commit 0f61d04

Please sign in to comment.