mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
Merge pull request #290 from BoostIO/featureSyntaxHighlightCheck
Feature syntax highlight check
This commit is contained in:
@@ -104,10 +104,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,28 +4,43 @@ 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 ReactCodeMirror from 'react-codemirror'
|
||||||
|
import CodeMirror from 'codemirror'
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
|
|
||||||
class UiTab extends React.Component {
|
class UiTab extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
config: props.config
|
config: props.config,
|
||||||
|
codemirrorTheme: props.config.editor.theme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillMount () {
|
||||||
|
CodeMirror.autoLoadMode(ReactCodeMirror, 'javascript')
|
||||||
|
}
|
||||||
|
|
||||||
handleUIChange (e) {
|
handleUIChange (e) {
|
||||||
let { config } = this.state
|
const { codemirrorTheme } = this.state
|
||||||
|
let checkHighLight = document.getElementById('checkHighLight')
|
||||||
|
|
||||||
config.ui = {
|
if (checkHighLight === null) {
|
||||||
|
checkHighLight = document.createElement('link')
|
||||||
|
checkHighLight.setAttribute('id', 'checkHighLight')
|
||||||
|
checkHighLight.setAttribute('rel', 'stylesheet')
|
||||||
|
document.head.appendChild(checkHighLight)
|
||||||
|
}
|
||||||
|
|
||||||
|
const newConfig = {
|
||||||
|
ui: {
|
||||||
theme: this.refs.uiTheme.value,
|
theme: this.refs.uiTheme.value,
|
||||||
disableDirectWrite: this.refs.uiD2w != null
|
disableDirectWrite: this.refs.uiD2w != null
|
||||||
? this.refs.uiD2w.checked
|
? this.refs.uiD2w.checked
|
||||||
: false
|
: false
|
||||||
}
|
},
|
||||||
config.editor = {
|
editor: {
|
||||||
theme: this.refs.editorTheme.value,
|
theme: this.refs.editorTheme.value,
|
||||||
fontSize: this.refs.editorFontSize.value,
|
fontSize: this.refs.editorFontSize.value,
|
||||||
fontFamily: this.refs.editorFontFamily.value,
|
fontFamily: this.refs.editorFontFamily.value,
|
||||||
@@ -33,15 +48,22 @@ class UiTab extends React.Component {
|
|||||||
indentSize: this.refs.editorIndentSize.value,
|
indentSize: this.refs.editorIndentSize.value,
|
||||||
switchPreview: this.refs.editorSwitchPreview.value,
|
switchPreview: this.refs.editorSwitchPreview.value,
|
||||||
keyMap: this.refs.editorKeyMap.value
|
keyMap: this.refs.editorKeyMap.value
|
||||||
}
|
},
|
||||||
config.preview = {
|
preview: {
|
||||||
fontSize: this.refs.previewFontSize.value,
|
fontSize: this.refs.previewFontSize.value,
|
||||||
fontFamily: this.refs.previewFontFamily.value,
|
fontFamily: this.refs.previewFontFamily.value,
|
||||||
codeBlockTheme: this.refs.previewCodeBlockTheme.value,
|
codeBlockTheme: this.refs.previewCodeBlockTheme.value,
|
||||||
lineNumber: this.refs.previewLineNumber.checked
|
lineNumber: this.refs.previewLineNumber.checked
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({ config })
|
const newCodemirrorTheme = this.refs.editorTheme.value
|
||||||
|
|
||||||
|
if (newCodemirrorTheme !== codemirrorTheme) {
|
||||||
|
checkHighLight.setAttribute('href', `../node_modules/codemirror/theme/${newCodemirrorTheme}.css`)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme })
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveUIClick (e) {
|
handleSaveUIClick (e) {
|
||||||
@@ -61,8 +83,8 @@ class UiTab extends React.Component {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
const themes = consts.THEMES
|
const themes = consts.THEMES
|
||||||
const { config } = this.state
|
const { config, codemirrorTheme } = this.state
|
||||||
|
const codemirrorSampleCode = '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};'
|
||||||
return (
|
return (
|
||||||
<div styleName='root'>
|
<div styleName='root'>
|
||||||
<div styleName='group'>
|
<div styleName='group'>
|
||||||
@@ -113,6 +135,9 @@ class UiTab extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
|
<div styleName='code-mirror'>
|
||||||
|
<ReactCodeMirror value={codemirrorSampleCode} options={{ lineNumbers: true, readOnly: true, mode: 'javascript', theme: codemirrorTheme }} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div styleName='group-section'>
|
<div styleName='group-section'>
|
||||||
|
|||||||
@@ -68,6 +68,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