Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/monaco/Monaco.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ onMounted(async () => {
} else {
watch(
() => props.filename,
() => {
(_, oldFilename) => {
if (!editorInstance) return
const file = store.state.files[props.filename]
if (!file) return null
Expand All @@ -114,10 +114,16 @@ onMounted(async () => {
file.language,
file.code
)

const oldFile = oldFilename ? store.state.files[oldFilename] : null
if (oldFile) {
oldFile.editorViewState = editorInstance.saveViewState()
}

editorInstance.setModel(model)

if (file.selection) {
editorInstance.setSelection(file.selection)
if (file.editorViewState) {
editorInstance.restoreViewState(file.editorViewState)
editorInstance.focus()
}
},
Expand All @@ -135,14 +141,6 @@ onMounted(async () => {
emit('change', editorInstance.getValue())
})

editorInstance.onDidChangeCursorSelection((e) => {
const selection = e.selection
const file = store.state.files[props.filename]
if (file) {
file.selection = selection
}
})

// update theme
watch(replTheme, (n) => {
editorInstance.updateOptions({
Expand Down
4 changes: 2 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SFCTemplateCompileOptions,
} from 'vue/compiler-sfc'
import { OutputModes } from './output/types'
import type { Selection } from 'monaco-editor-core'
import type { editor } from 'monaco-editor-core'

const defaultMainFile = 'src/App.vue'

Expand Down Expand Up @@ -52,7 +52,7 @@ export class File {
css: '',
ssr: '',
}
selection: Selection | null = null
editorViewState: editor.ICodeEditorViewState | null = null

constructor(filename: string, code = '', hidden = false) {
this.filename = filename
Expand Down