Skip to content

Commit ef2c925

Browse files
committed
fix: prevent prettier altering other files when switching tabs
1 parent 5841941 commit ef2c925

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/editor/EditorContainer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const props = defineProps<{
1616
const store = inject('store') as Store
1717
const showMessage = ref(getItem())
1818
19-
const onChange = debounce((code: string) => {
20-
store.state.activeFile.code = code
19+
const onChange = debounce((code: string, filename: string) => {
20+
store.state.files[filename].code = code
2121
}, 250)
2222
2323
function setItem() {
@@ -38,7 +38,7 @@ watch(showMessage, () => {
3838
<FileSelector />
3939
<div class="editor-container">
4040
<props.editorComponent
41-
@change="onChange"
41+
@change="onChange($event, store.state.activeFile.filename)"
4242
:value="store.state.activeFile.code"
4343
:filename="store.state.activeFile.filename"
4444
/>

src/monaco/Monaco.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ onMounted(async () => {
173173
code = prettier.format(code, options)
174174
} catch (err) {}
175175
176-
emit('change', code)
176+
if (code !== props.value) {
177+
emit('change', code)
178+
}
177179
})
178180
179181
// update theme

0 commit comments

Comments
 (0)