save codemirror theme preferences into localstorage

This commit is contained in:
zema1 2018-08-29 09:22:10 +08:00
parent 2e782313ee
commit ec14ba848b
2 changed files with 20 additions and 2 deletions

View File

@ -18,7 +18,7 @@
<Col :span=12> <Col :span=12>
<div class="fl-right"> <div class="fl-right">
<span>Theme:</span> <span>Theme:</span>
<Select v-model="options.theme" @on-change="onThemeChange" class="adjust"> <Select :value="theme" @on-change="onThemeChange" class="adjust">
<Option v-for="item in themes" :key="item.label" :value="item.value">{{item.label}} <Option v-for="item in themes" :key="item.label" :value="item.value">{{item.label}}
</Option> </Option>
</Select> </Select>
@ -70,6 +70,10 @@
language: { language: {
type: String, type: String,
default: 'C++' default: 'C++'
},
theme: {
type: String,
default: 'material'
} }
}, },
data () { data () {
@ -120,6 +124,7 @@
}, },
onThemeChange (newTheme) { onThemeChange (newTheme) {
this.editor.setOption('theme', newTheme) this.editor.setOption('theme', newTheme)
this.$emit('changeTheme', newTheme)
}, },
onResetClick () { onResetClick () {
this.$emit('resetCode') this.$emit('resetCode')
@ -130,6 +135,11 @@
// get current editor object // get current editor object
return this.$refs.myEditor.editor return this.$refs.myEditor.editor
} }
},
watch: {
'theme' (newVal, oldVal) {
this.editor.setOption('theme', newVal)
}
} }
} }
</script> </script>

View File

@ -53,7 +53,9 @@
<CodeMirror :value.sync="code" <CodeMirror :value.sync="code"
:languages="problem.languages" :languages="problem.languages"
:language="language" :language="language"
:theme="theme"
@resetCode="onResetToTemplate" @resetCode="onResetToTemplate"
@changeTheme="onChangeTheme"
@changeLang="onChangeLang"></CodeMirror> @changeLang="onChangeLang"></CodeMirror>
<Row type="flex" justify="space-between"> <Row type="flex" justify="space-between">
<Col :span="10"> <Col :span="10">
@ -224,6 +226,7 @@
submitting: false, submitting: false,
code: '', code: '',
language: 'C++', language: 'C++',
theme: 'solarized',
submissionId: '', submissionId: '',
result: { result: {
result: 9 result: 9
@ -255,6 +258,7 @@
next(vm => { next(vm => {
vm.language = problemCode.language vm.language = problemCode.language
vm.code = problemCode.code vm.code = problemCode.code
vm.theme = problemCode.theme
}) })
} else { } else {
next() next()
@ -343,6 +347,9 @@
} }
this.language = newLang this.language = newLang
}, },
onChangeTheme (newTheme) {
this.theme = newTheme
},
onResetToTemplate () { onResetToTemplate () {
this.$Modal.confirm({ this.$Modal.confirm({
content: 'Are you sure you want to reset your code?', content: 'Are you sure you want to reset your code?',
@ -478,7 +485,8 @@
this.$store.commit(types.CHANGE_CONTEST_ITEM_VISIBLE, {menu: true}) this.$store.commit(types.CHANGE_CONTEST_ITEM_VISIBLE, {menu: true})
storage.set(buildProblemCodeKey(this.problem._id, from.params.contestID), { storage.set(buildProblemCodeKey(this.problem._id, from.params.contestID), {
code: this.code, code: this.code,
language: this.language language: this.language,
theme: this.theme
}) })
next() next()
}, },