@@ -30,26 +30,30 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
3030 value : '' ,
3131 visble : true ,
3232 } ;
33+ public container ! : HTMLDivElement ;
34+ public editorClientHeight ! : number ;
3335 public preview ! : PreviewMarkdown ;
3436 public toolbarsMode ! : ToolBarMode ;
3537 public CodeMirror ! : CodeMirror ;
3638 public render ( ) {
3739 const { prefixCls, className, toolbars, toolbarsMode, onChange, visble, ...codemirrorProps } = this . props ;
3840 return (
39- < div className = { classnames ( prefixCls , className ) } >
40- < ToolBarMode ref = { ( mode : ToolBarMode ) => this . toolbarsMode = mode } toolbarsMode = { toolbarsMode } onClick = { this . onClickMode } />
41- < ToolBar toolbars = { toolbars } onClick = { this . onClick } />
42- < div className = { classnames ( `${ prefixCls } -content` ) } >
43- < CodeMirror
44- ref = { this . getInstance }
45- { ...codemirrorProps }
46- onChange = { this . onChange }
47- />
48- < PreviewMarkdown
49- visble = { visble }
50- ref = { ( pmd : PreviewMarkdown ) => this . preview = pmd }
51- value = { this . props . value }
52- />
41+ < div ref = { ( node : HTMLDivElement ) => this . container = node } >
42+ < div className = { classnames ( prefixCls , className ) } >
43+ < ToolBarMode ref = { ( mode : ToolBarMode ) => this . toolbarsMode = mode } toolbarsMode = { toolbarsMode } onClick = { this . onClickMode } />
44+ < ToolBar toolbars = { toolbars } onClick = { this . onClick } />
45+ < div className = { classnames ( `${ prefixCls } -content` ) } >
46+ < CodeMirror
47+ ref = { this . getInstance }
48+ { ...codemirrorProps }
49+ onChange = { this . onChange }
50+ />
51+ < PreviewMarkdown
52+ visble = { visble }
53+ ref = { ( pmd : PreviewMarkdown ) => this . preview = pmd }
54+ value = { this . props . value }
55+ />
56+ </ div >
5357 </ div >
5458 </ div >
5559 ) ;
@@ -59,6 +63,20 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
5963 if ( this . preview ) {
6064 this . props . visble ? this . preview . show ( ) : this . preview . hide ( ) ;
6165 this . CodeMirror . editor . setSize ( this . props . visble ? '50%' : '100%' ) ;
66+ const { clientHeight } = this . CodeMirror . editor . getScrollInfo ( ) ;
67+ this . editorClientHeight = clientHeight ;
68+ window . addEventListener ( 'resize' , this . handleResize , true ) ;
69+ }
70+ }
71+
72+ public componentWillUnmount ( ) {
73+ window . removeEventListener ( 'resize' , this . handleResize , true ) ;
74+ }
75+
76+ public handleResize = ( ) => {
77+ const isfullscreen = this . toolbarsMode . state . fullscreen
78+ if ( isfullscreen ) {
79+ this . setEditorSize ( isfullscreen ) ;
6280 }
6381 }
6482
@@ -93,11 +111,21 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
93111 }
94112
95113 private fullScreen ( ) {
96- if ( this . toolbarsMode ) {
97- this . toolbarsMode . updateMode ( 'fullscreen' , ! this . toolbarsMode . state . fullscreen ) ;
114+ const { prefixCls } = this . props ;
115+ if ( this . toolbarsMode && this . container ) {
116+ const isfullscreen = ! this . toolbarsMode . state . fullscreen
117+ this . toolbarsMode . updateMode ( 'fullscreen' , isfullscreen ) ;
118+ this . container . className = isfullscreen ? classnames ( `${ prefixCls } -fullscreen` ) : '' ;
119+ document . body . style . overflow = isfullscreen ? 'hidden' : 'initial' ;
120+ this . setEditorSize ( isfullscreen ) ;
98121 }
99122 }
100123
124+ private setEditorSize ( isfullscreen : boolean ) {
125+ const clientHeight = document . body . clientHeight ;
126+ this . CodeMirror . editor . setSize ( this . preview . state . visble ? '50%' : '100%' , isfullscreen ? clientHeight - 33 : this . editorClientHeight ) ;
127+ }
128+
101129 private onClickMode = ( type : string ) => {
102130 if ( type === 'preview' ) {
103131 this . previewMarkdown ( ) ;
0 commit comments