@@ -15,6 +15,7 @@ import { getOrCreateModel } from './utils'
15
15
import { loadGrammars , loadTheme } from ' monaco-volar'
16
16
import { Store } from ' ../store'
17
17
import type { PreviewMode } from ' ../editor/types'
18
+ import { debounce } from ' ../utils'
18
19
19
20
const props = withDefaults (
20
21
defineProps <{
@@ -36,6 +37,7 @@ const containerRef = ref<HTMLDivElement>()
36
37
const ready = ref (false )
37
38
const editor = shallowRef <monaco .editor .IStandaloneCodeEditor >()
38
39
const store = inject <Store >(' store' )!
40
+ const editorHeight = ref (' 0px' )
39
41
40
42
initMonaco (store )
41
43
@@ -129,8 +131,20 @@ onMounted(async () => {
129
131
// ignore save event
130
132
})
131
133
134
+ const updateEditorHeight = debounce (() => {
135
+ const lineCount = editorInstance .getModel ()?.getLineCount () || 8
136
+ const lineHeight = editorInstance .getOption (
137
+ monaco .editor .EditorOption .lineHeight
138
+ )
139
+ editorHeight .value = (lineCount + 1 ) * lineHeight + ' px'
140
+ })
141
+
142
+ updateEditorHeight ()
143
+
132
144
editorInstance .onDidChangeModelContent (() => {
133
145
emit (' change' , editorInstance .getValue ())
146
+
147
+ updateEditorHeight ()
134
148
})
135
149
136
150
editorInstance .onDidChangeCursorSelection ((e ) => {
@@ -151,10 +165,10 @@ onBeforeUnmount(() => {
151
165
<div class =" editor" ref =" containerRef" ></div >
152
166
</template >
153
167
154
- <style >
168
+ <style scoped >
155
169
.editor {
156
170
position : relative ;
157
- height : 100 % ;
171
+ height : v-bind( ' editorHeight ' ) ;
158
172
width : 100% ;
159
173
overflow : hidden ;
160
174
}
0 commit comments