Page MenuHomePhabricator

browser search sometimes doesn't detect text in .cm-editor (keywords: find, ctrl-f)
Closed, ResolvedPublicFeature

Description

Steps to replicate the issue (include links if applicable):

What happens?:

  • 0 results

What should have happened instead?:

  • 1 result on line 51

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

  • Unsure if this is skin or browser dependent. For me, I am using Google Chrome and Vector 2010.

Other information (browser name/version, screenshots, etc.):

  • I understand that a workaround is to use CodeMirror's built in search feature, but this is not ideal for me. Would be great to see the browser's search feature work in CodeMirror.

Event Timeline

Assuming you have CM6 enabled, this was changed circa August 9 (date based on a discussion in Discord) when the new search bar was being implemented in T371436: Redesign CodeMirror search panel. Apparently it's related to performance. I pinged you to the discussion on Discord (and have elided any quotations of interest to respect opinions stated elsewhere).

And if you're not using CM6, CM5 is doomed for this world.

MusikAnimal moved this task from Backlog to Done on the MediaWiki-extensions-CodeMirror board.
MusikAnimal subscribed.

This is a requirement for performance, I'm afraid.

What we can do however auto-focus on the textarea? That may need to be an opt-in thing for accessibility reasons.

Another thought was to introduce a separate shortcut – say Ctrl-Shift-F – that opens the CodeMirror search.

May I ask what this ticket would entail on the technical side to implement? Is the limitation due to contenteditable and all the fun that comes with that? :)

Ctrl-F is a very basic browser function and it is odd to see it broken. It also leads to silent false negatives, i.e. you search for a word and it shows zero results, so you think there's zero results, but there's actually results.

Is the limitation due to contenteditable and all the fun that comes with that? :)

No, it is not specifically related to contenteditable. CodeEditor (Ace) and Monaco also have similar implementations. My understanding is that real-time syntax highlighting can be very expensive for a large document, so advanced web code editors all try to highlight only a small viewport instead of the full document.

This is a requirement for performance, I'm afraid.

What we can do however auto-focus on the textarea? That may need to be an opt-in thing for accessibility reasons.

I understand that applying syntax highlighting to a large document can cause performance issues (I've certainly encountered this in CodeMirror v5 before). But whether text outside of the visible area is findable and whether it is being syntax highlighted are separate issues. It would be perfectly fine for the text outside of visible area to not be syntax-highlighted, as long as it's still findable with the Find function.

IMO, as much as I am bothered by CodeMirror v5's performance issues, those are preferable to completely breaking the browser's Find function.

It would be perfectly fine for the text outside of visible area to not be syntax-highlighted, as long as it's still findable with the Find function.

Unfortunately, CodeMirror library does not provide this option, just like all the other sophisticated browser code editors.

MusikAnimal moved this task from Done to Improvement on the MediaWiki-extensions-CodeMirror board.
MusikAnimal changed the subtype of this task from "Bug Report" to "Feature Request".

I'm going to re-open because I think there are alternatives we can look into.

If we could see what the user is searching for via Ctrl-F, we could make this work, since we already know what the full wikitext is. This is not possible for privacy reasons.

Some ideas:

  1. Auto-focus the editor on page load. Some have said this can cause accessibility problems, but one can always tab out of the editor (or hit Escape and Tab shortly thereafter if the editor inserts tab characters).
  2. Add a new keyboard shortcut for searching editor contents, say Shift-Ctrl-F. Related: T399103
  3. Detect use of Ctrl-F outside CodeMirror, and show a notification that you must click inside the editor (or use Shift-Ctrl-F, if we add that) to search its contents.

Do any or all of these sound okay?

Thanks for reopening.

#1 first preference

#2 and #3 together second preference

Novem_Linguae renamed this task from browser search sometimes doesn't detect text in .cm-editor to browser search sometimes doesn't detect text in .cm-editor (keywords: find, ctrl-f).Aug 22 2025, 4:19 AM

I went to go try to find something inside of .cm-editor on mobile today. I used Firefox for Android with "Desktop site" ticked. I was unable to do a proper find since I couldn't get the CodeMirror find dialog to open.

Perhaps we should add a button/icon for CodeMirror find to the wikitext toolbar, so that it can be clicked on mobile? Can't really do hotkeys (Ctrl-F) on mobile.

Perhaps we should add a button/icon for CodeMirror find to the wikitext toolbar?

It is already there, in the Advanced section.

Thanks for the tip. I don't see an "Advanced" section though.

image.png (1×2 px, 526 KB)

I don't see an "Advanced" section though.

I thought you were talking about a button from the WikiEditor toolbar? You will only see a toolbar when you load the WikiEditor.

You turned off the 2010 toolbar it looks like? Or had the 2006 toolbar enabled when that was subsequently removed from the core software. Check preferences at

image.png (53×381 px, 3 KB)
It will look like this
image.png (162×1 px, 41 KB)

Turning the 2010 toolbar preference on worked. The search and replace icon is hiding in the top right corner. A little hard to spot, but good enough. Thanks!

image.png (179×2 px, 59 KB)

Change #1187988 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] Add 'autofocus' preference to put focus on editor after activation

https://gerrit.wikimedia.org/r/1187988

MusikAnimal changed the task status from Open to In Progress.Sep 14 2025, 7:46 PM
MusikAnimal claimed this task.

The above patch adds a preference (default ON) to put initial focus on the editor.

Change #1187988 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Add 'autofocus' preference to put focus on editor after activation

https://gerrit.wikimedia.org/r/1187988

I tested this out, and it works great! Any chance it gets cherry-picked to REL1_44?

Change #1188860 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@REL1_44] Add 'autofocus' preference to put focus on editor after activation

https://gerrit.wikimedia.org/r/1188860

I tested this out, and it works great! Any chance it gets cherry-picked to REL1_44?

I've made an attempt with r1188860. Are you able to test it?

Yeah, it seems to still work when I apply the patch from r1188860 to REL1_44.

Change #1188860 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@REL1_44] Add 'autofocus' preference to put focus on editor after activation

https://gerrit.wikimedia.org/r/1188860

Okay, thanks! I've just merged it into REL1_44 :)