Skip to content

Commit 377fe66

Browse files
committed
Let CodeMirror auto-size with max-height constraint instead of calculating
1 parent 86b288c commit 377fe66

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

src/lib/components/dialogs/CodePreviewDialog.svelte

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@
2323
let currentTheme = $state<Theme>('dark');
2424
let copied = $state(false);
2525
26-
// Line count for dynamic height
27-
const MAX_LINES = 35;
28-
const LINE_HEIGHT_PX = 18.2; // CodeMirror default with 14px font
29-
const HEADER_HEIGHT_PX = 41; // Dialog header
30-
31-
let lineCount = $derived(code.split('\n').length);
32-
let dialogHeight = $derived(() => {
33-
const lines = Math.min(lineCount, MAX_LINES);
34-
return Math.ceil(lines * LINE_HEIGHT_PX + HEADER_HEIGHT_PX);
35-
});
26+
// Max height before scrolling
27+
const MAX_CONTENT_HEIGHT = 600;
3628
3729
// Subscribe to theme changes
3830
const unsubscribeTheme = themeStore.subscribe((theme) => {
@@ -135,7 +127,7 @@
135127

136128
{#if open}
137129
<div class="dialog-backdrop nested" transition:fade={{ duration: 150 }} onclick={handleBackdropClick} role="presentation">
138-
<div class="dialog glass-panel" style="height: {dialogHeight()}px" transition:scale={{ start: 0.95, duration: 150, easing: cubicOut }} role="dialog" tabindex="-1" aria-labelledby="dialog-title">
130+
<div class="dialog glass-panel" transition:scale={{ start: 0.95, duration: 150, easing: cubicOut }} role="dialog" tabindex="-1" aria-labelledby="dialog-title">
139131
<div class="dialog-header">
140132
<span id="dialog-title">{title}</span>
141133
<div class="header-actions">
@@ -191,17 +183,16 @@
191183
}
192184
193185
.dialog-body {
194-
flex: 1;
195186
overflow: hidden;
196187
}
197188
198189
.code-preview {
199-
height: 100%;
200190
overflow: hidden;
191+
max-height: 600px;
201192
}
202193
203194
.code-preview :global(.cm-editor) {
204-
height: 100%;
195+
max-height: 600px;
205196
}
206197
207198
.code-preview :global(.cm-scroller) {

src/lib/components/dialogs/ExportDialog.svelte

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@
3838
let pythonCode = $state('');
3939
let copied = $state(false);
4040
41-
// Line count for dynamic height
42-
const MAX_LINES = 35;
43-
const LINE_HEIGHT_PX = 18.2; // CodeMirror default with 14px font
44-
const HEADER_HEIGHT_PX = 41; // Dialog header
45-
46-
let lineCount = $derived(pythonCode.split('\n').length);
47-
let dialogHeight = $derived(() => {
48-
const lines = Math.min(lineCount, MAX_LINES);
49-
return Math.ceil(lines * LINE_HEIGHT_PX + HEADER_HEIGHT_PX);
50-
});
5141
5242
// Handle dialog open/close
5343
$effect(() => {
@@ -145,7 +135,7 @@
145135

146136
{#if open}
147137
<div class="dialog-backdrop" transition:fade={{ duration: 150 }} onclick={handleBackdropClick} role="presentation">
148-
<div class="dialog glass-panel" style="height: {dialogHeight()}px" transition:scale={{ start: 0.95, duration: 150, easing: cubicOut }} role="dialog" tabindex="-1" aria-labelledby="dialog-title">
138+
<div class="dialog glass-panel" transition:scale={{ start: 0.95, duration: 150, easing: cubicOut }} role="dialog" tabindex="-1" aria-labelledby="dialog-title">
149139
<div class="dialog-header">
150140
<span id="dialog-title">Export Python Code</span>
151141
<div class="header-actions">
@@ -211,17 +201,16 @@
211201
}
212202
213203
.dialog-body {
214-
flex: 1;
215204
overflow: hidden;
216205
}
217206
218207
.code-preview {
219-
height: 100%;
220208
overflow: hidden;
209+
max-height: 600px;
221210
}
222211
223212
.code-preview :global(.cm-editor) {
224-
height: 100%;
213+
max-height: 600px;
225214
}
226215
227216
.code-preview :global(.cm-scroller) {

0 commit comments

Comments
 (0)