Skip to content

Commit 241ae80

Browse files
authored
#589 Fix problem code editor (#590)
* admin 전용 CodeMirror scope 지정 * 초기 언어template 선택 초기회 * 문제풀이 페이지 언어 변경 시 언어별 코드 보존 및 템플릿 적용 * 언어선택 tooltip 위치 변경 * template 존재하지 않는 경우 처리 * deep selector 문법 적용
1 parent e31ec74 commit 241ae80

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

frontend/src/pages/admin/components/CodeMirror.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<template>
2-
<codemirror
3-
v-model="currentValue"
4-
:options="options"
5-
ref="editor"
6-
></codemirror>
2+
<div class="admin-code-mirror">
3+
<codemirror
4+
v-model="currentValue"
5+
:options="options"
6+
ref="editor"
7+
></codemirror>
8+
</div>
79
</template>
810
<script>
911
// import { codemirror } from 'vue-codemirror-lite'
@@ -65,8 +67,8 @@ export default {
6567
}
6668
</script>
6769

68-
<style>
69-
.CodeMirror {
70+
<style scoped>
71+
.admin-code-mirror /deep/ .CodeMirror {
7072
height: auto !important;
7173
font-family: "Courier New", Courier, monospace !important;
7274
font-size: 14px;
@@ -75,30 +77,30 @@ export default {
7577
color: #334155 !important;
7678
}
7779
78-
.CodeMirror-scroll {
80+
.admin-code-mirror /deep/ .CodeMirror-scroll {
7981
height: 300px;
8082
overflow-y: auto !important;
8183
}
8284
83-
.CodeMirror-lines {
85+
.admin-code-mirror /deep/ .CodeMirror-lines {
8486
padding: 8px 0 !important;
8587
}
8688
87-
.CodeMirror-gutters {
89+
.admin-code-mirror /deep/ .CodeMirror-gutters {
8890
background-color: #f8fafc !important;
8991
border-right: 1px solid #e2e8f0 !important;
9092
padding-right: 5px;
9193
}
9294
93-
.CodeMirror-linenumber {
95+
.admin-code-mirror /deep/ .CodeMirror-linenumber {
9496
color: #94a3b8 !important;
9597
}
9698
97-
.CodeMirror-activeline-background {
99+
.admin-code-mirror /deep/ .CodeMirror-activeline-background {
98100
background: #f1f5f9 !important;
99101
}
100102
101-
.CodeMirror-selected {
103+
.admin-code-mirror /deep/ .CodeMirror-selected {
102104
background: #cbd5e1 !important;
103105
}
104106
</style>

frontend/src/pages/admin/views/problem/Problem.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ export default {
747747
data.spj_code = ""
748748
}
749749
data.spj_language = data.spj_language || "C"
750+
this.template = {}
750751
this.problem = data
751752
this.testCaseUploaded = true
752753
})
@@ -778,7 +779,7 @@ export default {
778779
if (this.template[langName] === undefined) {
779780
if (this.problem.template[langName] === undefined) {
780781
data[langName] = {
781-
checked: isSelected,
782+
checked: false,
782783
code: langConfig.config.template,
783784
mode: langConfig.content_type,
784785
}

frontend/src/pages/oj/views/problem/problemSolving/Problem.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export default {
136136
submitting: false,
137137
code: "",
138138
language: "C++",
139+
codePerLanguage: {},
139140
languages: {
140141
type: Array,
141142
default: () => {
@@ -276,11 +277,22 @@ export default {
276277
event.returnValue = ""
277278
},
278279
changeLanguage(newLang) {
279-
if (this.problem.template[newLang]) {
280-
if (this.code.trim() === "") {
281-
this.code = this.problem.template[newLang]
282-
}
280+
// 현재 작성 중인 코드 저장
281+
this.codePerLanguage[this.language] = this.code
282+
283+
// 변경 언어로 작성된 코드가 존재 하는 경우
284+
if (this.codePerLanguage[newLang] !== undefined) {
285+
this.code = this.codePerLanguage[newLang]
286+
}
287+
// 변경 언어로 작성된 코드가 존재하지 않음 + 변경언어 template 존재하는 경우
288+
else if (this.problem.template && this.problem.template[newLang]) {
289+
this.code = this.problem.template[newLang]
283290
}
291+
// 변경 언어로 작성된 코드가 존재하지 않음 + 변경언어 template 존재하지 않는 경우
292+
else {
293+
this.code = ""
294+
}
295+
284296
this.language = newLang
285297
this.$refs.myCm.onLangChange(newLang)
286298
},

frontend/src/pages/oj/views/problem/problemSolving/problemSolvingComponent/CodeEditorHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div
88
style="display: flex; justify-content: space-between; align-items: center"
99
>
10-
<Tooltip :content="'언어 선택'" placement="bottom">
10+
<Tooltip :content="'언어 선택'" placement="top">
1111
<Dropdown @on-click="changeLanguage" trigger="click" class="dropdown">
1212
<span
1313
style="font-size: 13px; padding-right: 3px; font-weight: 450"

0 commit comments

Comments
 (0)