How to deselect all content in a Monaco editor

Viewed 867

I have a monaco editor in my UI, and I'd like to programmatically unselect all selected ranges within it.

editor.getSelection() can apparently return null, according to its type definitions, but I've tried editor.setSelection(null) and editor.setSelections([]), and both fail complaining that the argument is invalid.

What is the correct way to do this?

1 Answers

Passing a new empty selection worked for me.

editor.setSelection(new monaco.Selection(0, 0, 0, 0));
Related