Skip to content

Commit dd2409c

Browse files
authored
Merge pull request louislam#786 from louislam/dockge andersmmg/replace-editor
Merged @andersmmg's pull request replacing the editor with codemirror.
2 parents 8f14547 + ec70131 commit dd2409c

File tree

4 files changed

+561
-441
lines changed

4 files changed

+561
-441
lines changed

frontend/src/pages/Compose.vue

Lines changed: 53 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,18 @@
171171

172172
<!-- YAML editor -->
173173
<div class="shadow-box mb-3 editor-box" :class="{'edit-mode' : isEditMode}">
174-
<prism-editor
174+
<code-mirror
175175
ref="editor"
176176
v-model="stack.composeYAML"
177-
class="yaml-editor"
178-
:highlight="highlighterYAML"
179-
line-numbers :readonly="!isEditMode"
180-
@input="yamlCodeChange"
181-
@focus="editorFocus = true"
182-
@blur="editorFocus = false"
183-
></prism-editor>
177+
:extensions="extensions"
178+
minimal
179+
wrap="true"
180+
dark="true"
181+
tab="true"
182+
:disabled="!isEditMode"
183+
:hasFocus="editorFocus"
184+
@change="yamlCodeChange"
185+
/>
184186
</div>
185187
<div v-if="isEditMode" class="mb-3">
186188
{{ yamlError }}
@@ -190,15 +192,18 @@
190192
<div v-if="isEditMode">
191193
<h4 class="mb-3">.env</h4>
192194
<div class="shadow-box mb-3 editor-box" :class="{'edit-mode' : isEditMode}">
193-
<prism-editor
195+
<code-mirror
194196
ref="editor"
195197
v-model="stack.composeENV"
196-
class="env-editor"
197-
:highlight="highlighterENV"
198-
line-numbers :readonly="!isEditMode"
199-
@focus="editorFocus = true"
200-
@blur="editorFocus = false"
201-
></prism-editor>
198+
:extensions="extensionsEnv"
199+
minimal
200+
wrap="true"
201+
dark="true"
202+
tab="true"
203+
:disabled="!isEditMode"
204+
:hasFocus="editorFocus"
205+
@change="yamlCodeChange"
206+
/>
202207
</div>
203208
</div>
204209

@@ -241,13 +246,13 @@
241246
</template>
242247

243248
<script>
244-
import { highlight, languages } from "prismjs/components/prism-core";
245-
import { PrismEditor } from "vue-prism-editor";
246-
import "prismjs/components/prism-yaml";
249+
import CodeMirror from "vue-codemirror6";
250+
import { yaml } from "@codemirror/lang-yaml";
251+
import { python } from "@codemirror/lang-python";
252+
import { dracula as editorTheme } from "thememirror";
253+
import { lineNumbers, EditorView } from "@codemirror/view";
247254
import { parseDocument, Document } from "yaml";
248255
249-
import "prismjs/themes/prism-tomorrow.css";
250-
import "vue-prism-editor/dist/prismeditor.min.css";
251256
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
252257
import {
253258
COMBINED_TERMINAL_COLS,
@@ -261,6 +266,7 @@ import {
261266
import { BModal } from "bootstrap-vue-next";
262267
import NetworkInput from "../components/NetworkInput.vue";
263268
import dotenv from "dotenv";
269+
import { ref } from "vue";
264270
265271
const template = `
266272
services:
@@ -275,17 +281,12 @@ const envDefault = "# VARIABLE=value #comment";
275281
let yamlErrorTimeout = null;
276282
277283
let serviceStatusTimeout = null;
278-
let prismjsSymbolDefinition = {
279-
"symbol": {
280-
pattern: /(?<!\$)\$(\{[^{}]*\}|\w+)/,
281-
}
282-
};
283284
284285
export default {
285286
components: {
286287
NetworkInput,
287288
FontAwesomeIcon,
288-
PrismEditor,
289+
CodeMirror,
289290
BModal,
290291
},
291292
beforeRouteUpdate(to, from, next) {
@@ -294,10 +295,35 @@ export default {
294295
beforeRouteLeave(to, from, next) {
295296
this.exitConfirm(next);
296297
},
298+
setup() {
299+
const editorFocus = ref(false);
300+
301+
const focusEffectHandler = (state, focusing) => {
302+
editorFocus.value = focusing;
303+
return null;
304+
};
305+
306+
const extensions = [
307+
editorTheme,
308+
yaml(),
309+
lineNumbers(),
310+
EditorView.focusChangeEffect.of(focusEffectHandler)
311+
];
312+
313+
const extensionsEnv = [
314+
editorTheme,
315+
python(),
316+
lineNumbers(),
317+
EditorView.focusChangeEffect.of(focusEffectHandler)
318+
];
319+
320+
return { extensions,
321+
extensionsEnv,
322+
editorFocus };
323+
},
297324
yamlDoc: null, // For keeping the yaml comments
298325
data() {
299326
return {
300-
editorFocus: false,
301327
jsonConfig: {},
302328
envsubstJSONConfig: {},
303329
yamlError: "",
@@ -318,7 +344,6 @@ export default {
318344
};
319345
},
320346
computed: {
321-
322347
endpointDisplay() {
323348
return this.$root.endpointDisplayFunction(this.endpoint);
324349
},
@@ -668,46 +693,6 @@ export default {
668693
this.isEditMode = false;
669694
},
670695
671-
highlighterYAML(code) {
672-
if (!languages.yaml_with_symbols) {
673-
languages.yaml_with_symbols = languages.insertBefore("yaml", "punctuation", {
674-
"symbol": prismjsSymbolDefinition["symbol"]
675-
});
676-
}
677-
return highlight(code, languages.yaml_with_symbols);
678-
},
679-
680-
highlighterENV(code) {
681-
if (!languages.docker_env) {
682-
languages.docker_env = {
683-
"comment": {
684-
pattern: /(^#| #).*$/m,
685-
greedy: true
686-
},
687-
"keyword": {
688-
pattern: /^\w*(?=[:=])/m,
689-
greedy: true
690-
},
691-
"value": {
692-
pattern: /(?<=[:=]).*?((?= #)|$)/m,
693-
greedy: true,
694-
inside: {
695-
"string": [
696-
{
697-
pattern: /^ *'.*?(?<!\\)'/m,
698-
},
699-
{
700-
pattern: /^ *".*?(?<!\\)"|^.*$/m,
701-
inside: prismjsSymbolDefinition
702-
},
703-
],
704-
},
705-
},
706-
};
707-
}
708-
return highlight(code, languages.docker_env);
709-
},
710-
711696
yamlToJSON(yaml) {
712697
let doc = parseDocument(yaml);
713698
if (doc.errors.length > 0) {

frontend/src/styles/main.scss

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,6 @@ optgroup {
593593
color: $primary;
594594
}
595595

596-
.prism-editor__textarea {
597-
outline: none !important;
598-
}
599596

600597
h5.settings-subheading::after {
601598
content: "";
@@ -676,18 +673,25 @@ code {
676673
color: $dark-font-color3;
677674
}
678675

679-
// Vue Prism Editor bug - workaround
680-
// https://github.com/koca/vue-prism-editor/issues/87
681-
/*
682-
.prism-editor__textarea {
683-
width: 999999px !important;
676+
677+
.cm-gutters {
678+
background-color: transparent !important;
679+
}
680+
.dark [contenteditable="true"] {
681+
background-color: transparent !important;
684682
}
685-
.prism-editor__editor {
686-
white-space: pre !important;
683+
.cm-editor {
684+
background-color: transparent !important;
685+
}
686+
.cm-activeLine, .cm-activeLineGutter {
687+
background-color: transparent !important;
688+
}
689+
.cm-selectionBackground {
690+
background-color: #74c2ff3d !important;
691+
}
692+
.cm-focused {
693+
outline: none !important;
687694
}
688-
.prism-editor__container {
689-
overflow-x: scroll !important;
690-
}*/
691695

692696
// Localization
693697
@import "localization.scss";

0 commit comments

Comments
 (0)