@@ -3,22 +3,34 @@ import React, {Component} from 'react';
3
3
import CodeMirror from 'codemirror' ;
4
4
import CodeMirrorModeMeta from 'codemirror/mode/meta.js' ;
5
5
import CodeMirrorLoadMode from 'codemirror/addon/mode/loadmode.js' ;
6
+ import { } from 'codemirror/addon/hint/show-hint.js' ;
6
7
import { connect } from 'react-redux' ;
7
8
import * as TabActions from '../Tab/actions' ;
8
9
9
10
class CodeMirrorEditor extends Component {
11
+ static defaultProps = {
12
+ theme : 'monokai' ,
13
+ height : '100%' ,
14
+ width : '100%' ,
15
+ } ;
16
+
17
+
10
18
constructor ( props ) {
11
19
super ( props ) ;
12
20
this . state = { } ;
13
21
}
14
22
15
23
componentDidMount ( ) {
16
- const { tab} = this . props ;
17
- const editor = this . editor = CodeMirror ( this . editorDOM ) ;
24
+ const { theme, tab, width, height} = this . props ;
25
+ const editor = this . editor = CodeMirror ( this . editorDOM , {
26
+ theme : theme ,
27
+ autofocus : true
28
+ } ) ;
18
29
if ( tab . content ) {
19
30
const { body, path} = tab . content ;
20
31
const modeInfo = this . getMode ( path ) ;
21
32
if ( body ) editor . setValue ( body ) ;
33
+ editor . setSize ( width , height ) ;
22
34
if ( modeInfo ) {
23
35
let mode = modeInfo . mode ;
24
36
require ( [ `codemirror/mode/${ mode } /${ mode } .js` ] , ( ) => {
@@ -30,19 +42,30 @@ class CodeMirrorEditor extends Component {
30
42
// little hack to make codemirror work with legacy interface
31
43
editor . isFocused = editor . hasFocus ;
32
44
tab . editor = editor ;
45
+ editor . on ( 'change' , this . onChange ) ;
33
46
editor . on ( 'focus' , ( ) => {
34
47
this . props . dispatch ( TabActions . activateTab ( tab . id ) )
35
48
} )
36
49
}
37
50
38
51
getMode ( path ) {
39
52
const m = / .+ \. ( [ ^ . ] + ) $ / . exec ( path ) ;
40
- const info = CodeMirror . findModeByExtension ( m [ 1 ] ) ;
41
- if ( info ) {
42
- return info
53
+ if ( m ) {
54
+ const info = CodeMirror . findModeByExtension ( m [ 1 ] ) ;
55
+ if ( info ) {
56
+ return info
57
+ }
43
58
}
44
59
}
45
60
61
+ onChange = ( e ) => {
62
+ const { tab, dispatch} = this . props ;
63
+ if ( ! tab . flags . modified ) {
64
+ dispatch ( TabActions . updateTabFlags ( tab . id , 'modified' , true ) )
65
+ }
66
+ } ;
67
+
68
+
46
69
render ( ) {
47
70
const { width, height} = this . props ;
48
71
const name = this . state . name ;
0 commit comments