22import { useMonaco } from ' @guolao/vue-monaco-editor' ;
33import { editor , Range } from ' monaco-editor' ;
44import type { CallLocation , MonacoTheme , SerializedRange } from ' shared/src' ;
5- import { computed , effect , nextTick , shallowRef , watch } from ' vue' ;
5+ import { computed , effect , shallowRef , watch } from ' vue' ;
66import { stacktraceMap } from ' ./main' ;
77
88const props = defineProps <{
@@ -83,30 +83,31 @@ function setDecorators(editor: editor.IStandaloneCodeEditor, position: Serialize
8383}
8484
8585
86- async function layoutEditor(editor : editor .IStandaloneCodeEditor ) {
87- const size = editor .getScrollHeight ();
86+ function layoutEditor(editor : editor .IStandaloneCodeEditor ) {
8887 const lineCount = editor .getModel ()?.getLineCount () ?? 0 ;
89- // add a padding line so the editor shows all lines properly!
90- // this is only a issue if we have a horizontal scroll bar.
91- const lineSize = (lineCount > 0 ) ? (size / lineCount ) : 14 ;
92- editor .layout ({ width: 0 , height: 0 }); // prevent growing
93- await nextTick ();
94- editor .layout ({ width: 100 , height: size + lineSize });
88+ const lineHeight = 18 ; // Standard line height for Monaco
89+
90+ // Calculate height based on line count, not scroll height
91+ const contentHeight = lineCount * lineHeight ;
92+ const targetHeight = Math .min (Math .max (contentHeight + 10 , 50 ), 400 ); // min 50px, max 400px
93+
94+ // Use CSS-based width instead of calculating container width
95+ editor .layout ({ width: 100 , height: targetHeight });
9596}
9697
97- async function setupEditor() {
98+ function setupEditor() {
9899 const editor = currentEditor .value ;
99100 if (! editor || ! props .traceFrame ) {
100101 return ;
101102 }
102103
103- async function update() {
104+ function update() {
104105 if (! editor ) {
105106 return
106107 }
107108 editor .revealLineNearTop (props .traceFrame .locationInCode .startLine + 1 );
108109 setDecorators (editor , props .traceFrame .locationInCode );
109- await layoutEditor (editor );
110+ layoutEditor (editor );
110111
111112 if (props .theme ) {
112113 setTheme (props .theme );
@@ -116,7 +117,7 @@ async function setupEditor() {
116117 const disposable = editor .onDidChangeModelContent (update );
117118 editor .onDidDispose (() => disposable .dispose ());
118119
119- await update ()
120+ update ()
120121}
121122
122123const code = computed (() => {
@@ -139,7 +140,14 @@ function setTheme(monacoTheme: MonacoTheme) {
139140 }
140141}
141142
142- watch ([currentEditor , code ], () => setupEditor ().catch (console .error .bind (undefined , " Error while setting up editor" )));
143+ watch ([currentEditor , code ], () => {
144+ try {
145+ setupEditor ();
146+ } catch (e ) {
147+ console .error (" Error while setting up editor" , e );
148+ }
149+ });
150+
143151watch ([props .theme , monaco ], () => {
144152 if (props .theme ) setTheme (props .theme );
145153});
@@ -148,6 +156,32 @@ watch(currentEditor, (editor) => {
148156 const domNode = editor ?.getDomNode ();
149157 domNode ?.addEventListener (" scroll" , e => e .stopImmediatePropagation (), { capture: true });
150158 domNode ?.addEventListener (" wheel" , e => e .stopImmediatePropagation (), { capture: true });
159+
160+ if (editor && domNode ) {
161+ let timeoutId: number ;
162+ const resizeObserver = new ResizeObserver (() => {
163+ clearTimeout (timeoutId );
164+ timeoutId = window .setTimeout (() => {
165+ const container = domNode .parentElement ;
166+ if (container ) {
167+ const containerRect = container .getBoundingClientRect ();
168+ const targetWidth = Math .max (containerRect .width - 10 , 100 );
169+ const currentLayout = editor .getLayoutInfo ();
170+ editor .layout ({ width: targetWidth , height: currentLayout .height });
171+ }
172+ }, 150 );
173+ });
174+
175+ const container = domNode .parentElement ;
176+ if (container ) {
177+ resizeObserver .observe (container );
178+ }
179+
180+ editor .onDidDispose (() => {
181+ clearTimeout (timeoutId );
182+ resizeObserver .disconnect ();
183+ });
184+ }
151185});
152186 </script >
153187
@@ -176,7 +210,9 @@ watch(currentEditor, (editor) => {
176210 " path path focus"
177211 " code code code" ;
178212 grid-template-columns : 1fr 1fr auto ;
179- grid-template-rows : 1fr min-content ;
213+ grid-template-rows : auto min-content ;
214+ min-height : 80px ;
215+ /* Prevent collapse */
180216}
181217
182218.title-element {
@@ -186,6 +222,18 @@ watch(currentEditor, (editor) => {
186222 text-overflow : ellipsis ;
187223 min-width : 0 ;
188224}
225+
226+ /* Ensure Monaco editor doesn't shrink too much */
227+ .frame-container .no-scroll {
228+ min-width : 100px ;
229+ min-height : 50px ;
230+ width : 100% ;
231+ }
232+
233+ /* Override Monaco editor internal sizing */
234+ .frame-container .no-scroll :deep(.monaco-editor ) {
235+ width : 100% !important ;
236+ }
189237 </style >
190238
191239<style >
0 commit comments