Skip to content

Commit c53b542

Browse files
committed
Make toggleBlockCommentByLine not affect lines with no text selected
FIX: Change `toggleBlockCommentByLine` to not affect lines with the selection end right at their start. See https://discuss.codemirror.net/t/togglecomment-after-triple-click-line-selection/8720
1 parent 2be11c5 commit c53b542

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/comment.ts

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ function selectedLineRanges(state: EditorState) {
113113
for (let r of state.selection.ranges) {
114114
let fromLine = state.doc.lineAt(r.from)
115115
let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to)
116+
if (toLine.from > fromLine.from && toLine.from == r.to)
117+
toLine = r.to == fromLine.to + 1 ? fromLine : state.doc.lineAt(r.to - 1)
116118
let last = ranges.length - 1
117119
if (last >= 0 && ranges[last].to > fromLine.from) ranges[last].to = toLine.to
118120
else ranges.push({from: fromLine.from + /^\s*/.exec(fromLine.text)![0].length, to: toLine.to})

test/test-comment.ts

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ describe("comment", () => {
185185
checkLine(`on|e\nt|w|o\nth|ree`,
186186
`${o} on|e\nt|w|o\nth|ree ${c}`)
187187
})
188+
189+
it("doesn't include lines that the selection stops at the start of", () => {
190+
checkLine(`|one\n|two`, `${o} |one ${c}\n|two`)
191+
})
192+
193+
it("does include lines with cursor selection at the start", () => {
194+
checkLine(`|one\ntwo`, `|${o} one ${c}\ntwo`)
195+
})
188196
})
189197
}
190198

0 commit comments

Comments
 (0)