diff --git a/src/comment.ts b/src/comment.ts index e2eef04..5e826f4 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -113,6 +113,8 @@ function selectedLineRanges(state: EditorState) { for (let r of state.selection.ranges) { let fromLine = state.doc.lineAt(r.from) let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to) + if (toLine.from > fromLine.from && toLine.from == r.to) + toLine = r.to == fromLine.to + 1 ? fromLine : state.doc.lineAt(r.to - 1) let last = ranges.length - 1 if (last >= 0 && ranges[last].to > fromLine.from) ranges[last].to = toLine.to else ranges.push({from: fromLine.from + /^\s*/.exec(fromLine.text)![0].length, to: toLine.to}) diff --git a/test/test-comment.ts b/test/test-comment.ts index 25fe878..75c6b08 100644 --- a/test/test-comment.ts +++ b/test/test-comment.ts @@ -185,6 +185,14 @@ describe("comment", () => { checkLine(`on|e\nt|w|o\nth|ree`, `${o} on|e\nt|w|o\nth|ree ${c}`) }) + + it("doesn't include lines that the selection stops at the start of", () => { + checkLine(`|one\n|two`, `${o} |one ${c}\n|two`) + }) + + it("does include lines with cursor selection at the start", () => { + checkLine(`|one\ntwo`, `|${o} one ${c}\ntwo`) + }) }) }