Skip to content

Commit 8f941b8

Browse files
author
Loïc Mangeonjean
committed
fix: monaco doesn't support empty selection array
1 parent 9461e8d commit 8f941b8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/tools.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,18 @@ export async function collapseCodeSections (editor: monaco.editor.IStandaloneCod
254254
ranges.push(monaco.Range.fromPositions(match.range.getStartPosition(), currentPosition))
255255
}
256256

257-
const selections = editor.getSelections()
258-
editor.setSelections(ranges.map(r => ({
259-
selectionStartLineNumber: r.startLineNumber,
260-
selectionStartColumn: r.startColumn,
261-
positionLineNumber: r.endLineNumber,
262-
positionColumn: r.endColumn
263-
})))
264-
await editor.getAction('editor.createFoldingRangeFromSelection').run()
265-
if (selections != null) {
266-
editor.setSelections(selections)
257+
if (ranges.length > 0) {
258+
const selections = editor.getSelections()
259+
editor.setSelections(ranges.map(r => ({
260+
selectionStartLineNumber: r.startLineNumber,
261+
selectionStartColumn: r.startColumn,
262+
positionLineNumber: r.endLineNumber,
263+
positionColumn: r.endColumn
264+
})))
265+
await editor.getAction('editor.createFoldingRangeFromSelection').run()
266+
if (selections != null) {
267+
editor.setSelections(selections)
268+
}
267269
}
268270
}
269271
}

0 commit comments

Comments
 (0)