CodeMirror: default to using the same height as the textarea

CodeMirrorWikiEditor: add a 'ext.CodeMirror.initialize' hook to allow
integrations to manipulate the DOM before CodeMirror is initialized.

This is necessary for ProofreadPage, for example (I5c0824bf38cf7).

Bug: T357794
Change-Id: I4deeda192bdc233101ba61739a636f8fd143c1de
This commit is contained in:
MusikAnimal 2024-02-22 16:18:41 -05:00
parent 5bfb8dddad
commit c9c9ed27d3
3 changed files with 11 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -30,7 +30,13 @@ export default class CodeMirror {
const extensions = [
this.contentAttributesExtension,
this.phrasesExtension,
this.specialCharsExtension
this.specialCharsExtension,
EditorView.theme( {
// Use the same height as the textarea
'.cm-content': {
height: this.$textarea.outerHeight() + 'px'
}
} )
];
const namespaces = mw.config.get( 'wgCodeMirrorLineNumberingNamespaces' );
@ -167,6 +173,8 @@ export default class CodeMirror {
* @stable
*/
initialize( extensions = this.defaultExtensions ) {
mw.hook( 'ext.CodeMirror.initialize' ).fire( this.$textarea );
// Set up the initial EditorState of CodeMirror with contents of the native textarea.
this.state = EditorState.create( {
doc: this.$textarea.textSelection( 'getContents' ),