selectNextOccurrence with caseSensitive and wordWrap options?

By default the matches of selectNextOccurrence (via Mod+d) are case-sensitive and woleWord-precise. But sometimes I would like to select differently…

Request 1: Add config options

What is the easiest way to add options for case-sensitivity and word-wrap to findNextOccurrence, which is used by selectNextOccurrence?

What I’ve tried
  1. I tried to set the caseSensitive and wholeWord config of the search module, but it seems that they only apply to the searchPanel, but not to a programmatic use of selectNextOccurrence().
  2. I also tried to rewrite the selectNextOccurence and findNextOccurrence functions and replace SearchCursor with RegExpCursor, which has a caseSensitive option. Unfortunately, this leads to inconsistent results (a case-insensitive search over foo Foo foo will sometimes find two or three occurrences, depending on where I start searching).

Request 2: Make defaults of findNextOccurrence and highlightSelectionMatch consistent

I noticed that the matches I obtain from default Mod+d are inconsistent with the highlights from default highlightSelectionMatch. This is because findNextOccurrence defaults to wholeWord=false, while highlightSelectionMatches defaults to wholeWord=true. Interestingly, the latter has a wholeWord config, so I could change it… but also there, I miss a caseSensitive config.

Other comments

I’m using CodeMirror6 via Svelte-Codemirror-Editor.

Thank you very much. I’m working with CodeMirror since two days only, and it has been a really nice experience so far.

I think this is pretty much working as intended. findNextOccurrence will, if a full word is selected, try to find another full word to select, and if not, just look for a match. selectNextOccurrence isn’t really designed to fully match the highlights, it’s more of a do-what-I-mean helper for selecting the next instance of the selected text. It is also entirely separate from the search query mechanism.

If you’re looking for a command that behaves differently, building your own implementation may be the way to go.

Thanks for your reply @marijn

I think this is pretty much working as intended.

Hmm… not really, if you come from VS Codium. There, when you hit Mod+d you get a tiny popup appearing in the top right corner of the editor with toggles for both options (case-sensitivity and whole-word). In my day-to-day work with the multicursor editor I have use-cases for all 2^2=4 options, and I am actively switching between all of them. The only thing which I find a bit counter-intuitive in the VS Codium implementation is that both options are reset if the selection-length is zero when Mod+d is hit for the first time (i.e. when the selectWord() pendant will run).

If you’re looking for a command that behaves differently, building your own implementation may be the way to go.

I deeply believe that providing options would be a feature worth implementing. In fact, I really do need the switches for the teaching tool I’m currently building which must be able to imitate the behavior of different IDEs.

I’d be happy to file a PR on Github, but I first wanted to reach out. Also, since I need some assistance in understanding where exactly to insert the options (see the What I’ve tried section in my original post).

EDIT: Shortened my answer and rewrote the first part to describe the correct VS Codium behavior.

Just found an inconsistency in CodeMirror6, which may support my case to make those options explicit.

[] marks the cursor-position/selection before and after Mod+d is pressed multiple times.

(1) f[|]oo Foo foobar Foobar foo[foo] Foo foobar Foobar [foo]

(2) [foo] Foo foobar Foobar foo[foo] Foo foobar Foobar [foo]

BUT:
(3) foo Foo [foo]bar Foobar foo[foo] Foo [foo]bar Foobar [foo]
(4) f[oo] Foo foobar Foobar foof[oo] F[oo] f[oo]bar F[oo]bar f[oo]

So while (1) and (2) use a do-what-I-mean logic that sets wordWrap=true, (3) and (4) behave differently, just because the initial selection is not a full word.

This can be very confusing and against your muscle memory if you are used to the behavior of VS Codium, where (2) is treated the same as (3).

I don’t advocate for imitating the exact behavior as in VS Codium, so don’t get me wrong. But it would be nice if I was able to, if I need to – hence my plea for options.