fix(editor): if formatted code is the same as initial code but source code is changed, should also trigger update.
diff --git a/src/editor/CodeAce.vue b/src/editor/CodeAce.vue
index 70cec9a..c818a5f 100644
--- a/src/editor/CodeAce.vue
+++ b/src/editor/CodeAce.vue
@@ -49,7 +49,6 @@
mounted() {
this.loading = true;
ensureACE().then(() => {
- this.loading = false;
const editor = ace.edit(this.$el);
editor.getSession().setMode('ace/mode/javascript');
editor.setOptions({
@@ -68,6 +67,8 @@
if (this.initialCode) {
this.setInitialCode(this.initialCode);
}
+
+ this.loading = false;
});
},
diff --git a/src/editor/Editor.vue b/src/editor/Editor.vue
index 46da4e3..0687980 100644
--- a/src/editor/Editor.vue
+++ b/src/editor/Editor.vue
@@ -219,9 +219,7 @@
data() {
return {
- mousedown: false,
leftContainerSize: 40,
- mobileMode: false,
shared: store,
initialCode: '',
@@ -273,6 +271,7 @@
this.mousedown = false;
});
+ // Save code as a sharable link when ctrl/cmd + s is pressed.
window.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
const previewRef = this.$refs.preview;
@@ -415,7 +414,18 @@
},
format() {
formatCode(store.sourceCode).then((code) => {
- this.initialCode = code;
+ if (
+ code === this.initialCode &&
+ store.sourceCode !== this.initialCode
+ ) {
+ // If formatted code is the same as initial code but source code is changed,
+ // should also trigger update
+ this.initialCode = store.sourceCode;
+ console.log('update initial code');
+ }
+ this.$nextTick(() => {
+ this.initialCode = code;
+ });
});
},
onPreviewReady() {