mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add HighLightCheckEditor
This commit is contained in:
@@ -1,59 +0,0 @@
|
|||||||
import React, { PropTypes } from 'react'
|
|
||||||
import CodeMirror from 'codemirror'
|
|
||||||
import _ from 'lodash'
|
|
||||||
const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
|
|
||||||
|
|
||||||
export default class CheckHighlightEditor extends React.Component {
|
|
||||||
constructor (props) {
|
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount () {
|
|
||||||
this.value = this.props.value
|
|
||||||
this.editor = CodeMirror(this.refs.root, {
|
|
||||||
value: this.props.value,
|
|
||||||
lineNumbers: true,
|
|
||||||
lineWrapping: true,
|
|
||||||
theme: this.props.theme,
|
|
||||||
indentUnit: 4,
|
|
||||||
tabSize: 4,
|
|
||||||
inputStyle: 'textarea'
|
|
||||||
})
|
|
||||||
|
|
||||||
this.setMode(this.props.mode)
|
|
||||||
|
|
||||||
let editorTheme = document.getElementById('editorTheme')
|
|
||||||
}
|
|
||||||
|
|
||||||
setMode(mode) {
|
|
||||||
let syntax = CodeMirror.findModeByName('ejs')
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let { className, fontFamily } = this.props
|
|
||||||
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
|
|
||||||
? [fontFamily].concat(defaultEditorFontFamily)
|
|
||||||
: defaultEditorFontFamily
|
|
||||||
return (
|
|
||||||
<div className="CheckHilghtEditor"
|
|
||||||
ref = 'root'
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckHighlightEditor.propTypes = {
|
|
||||||
value: PropTypes.string.isRequired,
|
|
||||||
mode: PropTypes.string,
|
|
||||||
theme: PropTypes.string.isRequired,
|
|
||||||
className: PropTypes.string,
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckHighlightEditor.defaultProps = {
|
|
||||||
readOnly: true,
|
|
||||||
theme: 'base16-dark',
|
|
||||||
fontSize: 14,
|
|
||||||
fontFamily: 'Monaco, Consolas',
|
|
||||||
indentSize: 4,
|
|
||||||
indentType: 'space'
|
|
||||||
}
|
|
||||||
@@ -98,10 +98,17 @@
|
|||||||
margin-left: 10px
|
margin-left: 10px
|
||||||
font-size: 12px
|
font-size: 12px
|
||||||
|
|
||||||
|
.code-mirror
|
||||||
|
width 400px
|
||||||
|
height 140px
|
||||||
|
margin-top 10px
|
||||||
|
margin-bottom 10px
|
||||||
|
|
||||||
colorDarkControl()
|
colorDarkControl()
|
||||||
border-color $ui-dark-borderColor
|
border-color $ui-dark-borderColor
|
||||||
background-color $ui-dark-backgroundColor
|
background-color $ui-dark-backgroundColor
|
||||||
color $ui-dark-text-color
|
color $ui-dark-text-color
|
||||||
|
|
||||||
body[data-theme="dark"]
|
body[data-theme="dark"]
|
||||||
.root
|
.root
|
||||||
color $ui-dark-text-color
|
color $ui-dark-text-color
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import styles from './ConfigTab.styl'
|
|||||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||||
import store from 'browser/main/store'
|
import store from 'browser/main/store'
|
||||||
import consts from 'browser/lib/consts'
|
import consts from 'browser/lib/consts'
|
||||||
import CheckHighlghtEditor from '../PreferencesModal/CheckHighlightEditor'
|
import CodeMirror from 'react-codemirror'
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
|
|
||||||
@@ -13,12 +13,28 @@ class UiTab extends React.Component {
|
|||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
config: props.config
|
config: props.config,
|
||||||
|
options: {
|
||||||
|
lineNumbers: true,
|
||||||
|
theme: props.config.editor.theme,
|
||||||
|
readOnly: true,
|
||||||
|
mode: 'javascript'
|
||||||
|
},
|
||||||
|
code: ' function iamHappy(happy) {\n\tif(happy){\n\t console.log("I am Happy!")\n\t}else{\n\t console.log("I am not Happy!")\n\t}\n};'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUIChange (e) {
|
handleUIChange (e) {
|
||||||
let { config } = this.state
|
let { config, options } = this.state
|
||||||
|
let checkHighLight = document.getElementById('checkHighLight')
|
||||||
|
|
||||||
|
if (checkHighLight == null) {
|
||||||
|
checkHighLight = document.createElement('link')
|
||||||
|
checkHighLight.setAttribute('id', 'checkHighLight')
|
||||||
|
checkHighLight.setAttribute('rel', 'stylesheet')
|
||||||
|
document.head.appendChild(checkHighLight)
|
||||||
|
}
|
||||||
|
|
||||||
config.ui = {
|
config.ui = {
|
||||||
theme: this.refs.uiTheme.value,
|
theme: this.refs.uiTheme.value,
|
||||||
disableDirectWrite: this.refs.uiD2w != null
|
disableDirectWrite: this.refs.uiD2w != null
|
||||||
@@ -41,7 +57,23 @@ class UiTab extends React.Component {
|
|||||||
lineNumber: this.refs.previewLineNumber.checked
|
lineNumber: this.refs.previewLineNumber.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let newOptions = {
|
||||||
|
lineNumbers: true,
|
||||||
|
theme: config.editor.theme,
|
||||||
|
readOnly: true,
|
||||||
|
mode: 'javascript'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newOptions.theme !== options.theme) {
|
||||||
|
checkHighLight.setAttribute('href', '../node_modules/codemirror/theme/' + newOptions.theme + '.css')
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({options: newOptions})
|
||||||
|
|
||||||
this.setState({ config })
|
this.setState({ config })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveUIClick (e) {
|
handleSaveUIClick (e) {
|
||||||
@@ -61,7 +93,7 @@ class UiTab extends React.Component {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
const themes = consts.THEMES
|
const themes = consts.THEMES
|
||||||
const { config } = this.state
|
const { config, options } = this.state
|
||||||
return (
|
return (
|
||||||
<div styleName='root'>
|
<div styleName='root'>
|
||||||
<div styleName='group'>
|
<div styleName='group'>
|
||||||
@@ -112,11 +144,9 @@ class UiTab extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
<CheckHighlghtEditor
|
<div styleName='code-mirror'>
|
||||||
value="var a = 3"
|
<CodeMirror value={this.state.code} options={options}/>
|
||||||
ref='code'
|
</div>
|
||||||
theme={this.state.config.editor.theme}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div styleName='group-section'>
|
<div styleName='group-section'>
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
"node-ipc": "^8.1.0",
|
"node-ipc": "^8.1.0",
|
||||||
"raphael": "^2.2.7",
|
"raphael": "^2.2.7",
|
||||||
"react": "^15.0.2",
|
"react": "^15.0.2",
|
||||||
|
"react-codemirror": "^0.3.0",
|
||||||
"react-dom": "^15.0.2",
|
"react-dom": "^15.0.2",
|
||||||
"react-redux": "^4.4.5",
|
"react-redux": "^4.4.5",
|
||||||
"redux": "^3.5.2",
|
"redux": "^3.5.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user