Skip to content

Commit 227d1a9

Browse files
committed
fix(vue-playground): can not focus new file
1 parent 246b12b commit 227d1a9

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"source.fixAll.stylelint": true
4848
},
4949
"[vue]": {
50+
"editor.defaultFormatter": "esbenp.prettier-vscode",
5051
"editor.codeActionsOnSave": {
5152
"source.fixAll.eslint": true,
5253
"source.fixAll.stylelint": true

packages/vue-playground/src/playground/hooks/useMonaco.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export function useMonaco(target: Ref<HTMLElement | undefined>, options: UseMona
121121
async () => {
122122
const activeFileName = unref(activeFile)?.filename
123123
const activeModel = getModels()?.find(model => model.uri.path.endsWith(activeFileName))
124+
124125
if (editor && activeModel && !activeModel.isDisposed() && editor.getModel() !== activeModel) {
125126
editor.setModel(activeModel)
126127
editor.onDidChangeModelContent(() => {

packages/vue-playground/src/playground/hooks/useMonacoModels.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ export function useMonacoModels(options: UseMonacoModelsOptions) {
3636
() => {
3737
if (!unref(isSetup) || !getEditor() || !unref(projectId)) return
3838

39-
if (!models || !models.length) {
39+
const findModel = (file: File) =>
40+
models?.find(model => getFileUri(monaco, unref(projectId), file.filename).path === model.uri.path)
41+
42+
if (!models || !models.length || models.length !== unref(files).length) {
4043
const newModels = unref(files).map(file => {
41-
return monaco.editor.createModel(
42-
file.code,
43-
getFileLanguage(file),
44-
getFileUri(monaco, unref(projectId), file.filename)
44+
return (
45+
findModel(file) ||
46+
monaco.editor.createModel(
47+
file.code,
48+
getFileLanguage(file),
49+
getFileUri(monaco, unref(projectId), file.filename)
50+
)
4551
)
4652
})
47-
console.log('newModels', newModels)
4853
setModels(newModels)
4954
} else {
5055
models.forEach(model => {

0 commit comments

Comments
 (0)