Skip to content

Commit 8198ed1

Browse files
author
zhenjier
committed
Fine tune codemirror style. Problems remaining: 1) rule for including css, becuase every theme for codemirror is essetially a css file 2) autocompletion, looks like we need to implement this ourself, even the basic one(eg. completion in the same file).
1 parent 53d289d commit 8198ed1

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

app/components/CodeMirrorEditor/index.jsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@ import React, {Component} from 'react';
33
import CodeMirror from 'codemirror';
44
import CodeMirrorModeMeta from 'codemirror/mode/meta.js';
55
import CodeMirrorLoadMode from 'codemirror/addon/mode/loadmode.js';
6+
import {} from 'codemirror/addon/hint/show-hint.js';
67
import {connect} from 'react-redux';
78
import * as TabActions from '../Tab/actions';
89

910
class CodeMirrorEditor extends Component {
11+
static defaultProps = {
12+
theme: 'monokai',
13+
height: '100%',
14+
width: '100%',
15+
};
16+
17+
1018
constructor(props) {
1119
super(props);
1220
this.state = {};
1321
}
1422

1523
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+
});
1829
if (tab.content) {
1930
const {body, path} = tab.content;
2031
const modeInfo = this.getMode(path);
2132
if (body) editor.setValue(body);
33+
editor.setSize(width, height);
2234
if (modeInfo) {
2335
let mode = modeInfo.mode;
2436
require([`codemirror/mode/${mode}/${mode}.js`], () => {
@@ -30,19 +42,30 @@ class CodeMirrorEditor extends Component {
3042
// little hack to make codemirror work with legacy interface
3143
editor.isFocused = editor.hasFocus;
3244
tab.editor = editor;
45+
editor.on('change', this.onChange);
3346
editor.on('focus', () => {
3447
this.props.dispatch(TabActions.activateTab(tab.id))
3548
})
3649
}
3750

3851
getMode(path) {
3952
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+
}
4358
}
4459
}
4560

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+
4669
render() {
4770
const {width, height} = this.props;
4871
const name = this.state.name;

app/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow weak */
22
export default {
33
projectName: '',
4-
baseURL: 'http://localhost:3000' || window.location.origin,
4+
baseURL: '' || window.location.origin,
55
spaceKey: ''
66
}

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
还提供了可分享的开发环境功能,用户可以保存当前的 Terminal 环境,分享给团队的其他成员。">
1010
<link rel="icon" type="image/x-icon" href="favicon.ico">
1111
<link rel="stylesheet" href="../node_modules/codemirror/lib/codemirror.css">
12+
<link rel="stylesheet" href="../node_modules/codemirror/theme/monokai.css">
1213
<script src="https://use.fontawesome.com/838df4727b.js"></script>
1314
</head>
1415
<body>

0 commit comments

Comments
 (0)