mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
CodeMirrorWikiEditor: Remove hack to fix height in WikiEditor
WikiEditor's ResizingDragBar makes the editor resizable, so we need to set the height to 100%. This was attempted in Ib49d1d9e71 and I4deeda192b but both ultimately suffer from race conditions. Instead we're setting the height in WikiEditor with Ia5e9767e08. The heightExtension in the CodeMirror class still remains, in the event a subclass wishes to override the default behaviour in CM directly and not with CSS. Bug: T357794 Depends-On: Ia5e9767e0814eac29d58bc0d9c1023344a29dd84 Change-Id: Ic55dd098d70fd173ddee7100e392b889ee6ddd08
This commit is contained in:
parent
c63e81539a
commit
aa3876a97e
2
resources/dist/main.js
vendored
2
resources/dist/main.js
vendored
File diff suppressed because one or more lines are too long
2
resources/dist/main.js.map.json
vendored
2
resources/dist/main.js.map.json
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
import CodeMirror from './codemirror';
|
||||
import { EditorState, EditorSelection, Extension } from '@codemirror/state';
|
||||
import { EditorState, EditorSelection } from '@codemirror/state';
|
||||
import { EditorView, drawSelection, keymap } from '@codemirror/view';
|
||||
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
||||
import { searchKeymap } from '@codemirror/search';
|
||||
|
@ -101,23 +101,6 @@ export default class CodeMirrorWikiEditor extends CodeMirror {
|
|||
mw.hook( 'ext.CodeMirror.switch' ).fire( true, $( this.view.dom ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Realtime Preview's ResizingDragBar makes the editor resizable,
|
||||
* so we need to set the height to 100%.
|
||||
*
|
||||
* @return {Extension}
|
||||
*/
|
||||
get heightExtension() {
|
||||
if ( mw.loader.getState( 'ext.wikiEditor.realtimepreview' ) === 'ready' ) {
|
||||
return EditorView.theme( {
|
||||
'&': { height: '100%' }
|
||||
} );
|
||||
}
|
||||
return super.heightExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the CodeMirror button to WikiEditor
|
||||
*/
|
||||
|
|
|
@ -50,39 +50,6 @@ describe( 'addCodeMirrorToWikiEditor', () => {
|
|||
} );
|
||||
} );
|
||||
|
||||
describe( 'enableCodeMirror', () => {
|
||||
cmWe.$textarea.wikiEditor = jest.fn();
|
||||
|
||||
it( 'should use the height of the textarea if Realtime Preview disabled', () => {
|
||||
mw.loader.getState.mockImplementation( ( module ) => {
|
||||
if ( module === 'ext.wikiEditor' ) {
|
||||
return 'ready';
|
||||
}
|
||||
if ( module === 'ext.wikiEditor.realtimepreview' ) {
|
||||
return null;
|
||||
}
|
||||
} );
|
||||
$textarea.css( 'height', '999px' );
|
||||
cmWe.initialize();
|
||||
// Height includes padding and border.
|
||||
expect( $( cmWe.view.dom ).css( 'height' ) ).toStrictEqual( '1005px' );
|
||||
} );
|
||||
|
||||
it( 'should use 100% height if Realtime Preview is enabled', () => {
|
||||
mw.loader.getState.mockImplementation( ( module ) => {
|
||||
if ( module === 'ext.wikiEditor' ) {
|
||||
return 'ready';
|
||||
}
|
||||
if ( module === 'ext.wikiEditor.realtimepreview' ) {
|
||||
return 'ready';
|
||||
}
|
||||
} );
|
||||
$textarea.css( 'height', '999px' );
|
||||
cmWe.initialize();
|
||||
expect( $( cmWe.view.dom ).css( 'height' ) ).toStrictEqual( '100%' );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( 'updateToolbarButton', () => {
|
||||
it( 'should update the toolbar button based on the current CodeMirror state', () => {
|
||||
const btn = document.getElementById( 'mw-editbutton-codemirror' );
|
||||
|
|
Loading…
Reference in a new issue