I’ve done the following code segment. It loads codemirror just fine in a div, but the addons that I’d like do not seem to work. Anyone have some insight on what I may be doing incorrectly
Well match-highlighter is supposed to search and highlight instances of a word when one instance of that word is highlighted. But that doesn’t seem to happen with the code above.
How would I go about enabling the addons I’m loading? I figured “highlightSelectionMatches” was supposed to do that.
It is, yes, that’s the addon you did enable. Since NodeJS require doesn’t exist in the browser, I assume you’re using some kind of bundler or client-side module loader. Which one?
Could you verify that CodeMirror’s main lib is only loaded once (for example by putting a console.log in codemirror.js)? Sometimes module loaders end up resolving the library differently when required from addons, and they get a different instance and thus don’t register themselves with the instance you’re actually using.
You might be able to see whether your plugins managed to load by calling CodeMirror.defaults.hasOwnProperty("highlightSelectionMatches"). If that’s false, the plugin wasn’t loaded, or was loaded against a different instance of the core library.
Then I guess Electron is somehow failing to unify the various references to the codemirror libary, and your addons are loaded into a different instance from the one that you get. You could try changing your first line to var CODE = require("codemirror/lib/codemirror") and see if that helps.