How to highlight only the text content (not the entire line) when making multi-line selections in CodeMirror 6?

When I select multiple lines in CodeMirror, the selection highlight covers the entire line width.

I want the selection background to only highlight the actual text content, and not the empty space after the text on each line.

Is there a way to achieve this?

Any configuration, CSS, or custom extension suggestions would be appreciated. Thanks!

image

If you don’t include drawSelection in your configuration, you’ll get the browser’s native selection. It’s not perfect, but it might be closer to what you’re looking for.

1 Like