Steps to Reproduce:
- Set "Edit area font style:" to sans or serif font. https://www.mediawiki.org/wiki/Special:Preferences#mw-prefsection-editing
- Edit source with WTE 2010 or WTE 2017 https://www.mediawiki.org/w/index.php?title=2017_wikitext_editor&action=edit
- Switch on / off "Syntax highlighting" on toolbar (WTE 2010) or hamburger menu (WTE 2017).
Actual Results:
When highlighting is enabled the text is rendered with monospace font.
Expected Results:
The text is always rendered in the editor with a font according to the "Edit area font style:" setting.
Questions
After a superficial skimming of the javascript code, this seems to be intentional: the used class is always .mw-editfont-monospace.
- Why is that so?
- Are there any concerns that would block using the proper setting?
- How to query that setting in client javascript?
- Why is editing done in a different - hidden - layer behind the visible text?
Answers
There are 2 editors layered above each other.
- The top layer is visible to the users and does the syntax highlighting.
- The bottom layer is invisible and doesn't do syntax highlighting, thus the style of the hidden text is different from the visible.
Non-monospace fonts would render the styles and non-styled characters with different sizes, thereby causing misalignment between the two layers.
As the editing happens in the hidden bottom layer, the cursor and text selection are also rendered there. Misalignment can be seen when text is selected: the highlight in the bottom layer is in a different location than the text in the above layer.
To avoid such misalignment, the editor is restricted to monospace fonts, which render characters with different styling in the same area.
- Why is editing done in a different - hidden - layer behind the visible text?
The bottom layer is created by Visual Editor, the top layer by CodeMirror.
Allegedly CodeMirror is not compatible with some unspecified tools in VE, therefore the bottom layer is for compatibility.
- What's the problem with CodeMirror?
This would require identifying and evaluating the incompatibilities in said tools.