Skip to content

Commit 3f94538

Browse files
committed
Fix code dialog height calculation with accurate line height values
1 parent cbb4435 commit 3f94538

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/lib/components/dialogs/CodePreviewDialog.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
2626
// Line count for dynamic height
2727
const MAX_LINES = 35;
28-
const LINE_HEIGHT_PX = 20;
29-
const HEADER_HEIGHT_PX = 48;
30-
const PADDING_PX = 16;
28+
const LINE_HEIGHT_PX = 18.2; // CodeMirror default with 14px font
29+
const HEADER_HEIGHT_PX = 41; // Dialog header
30+
const CM_PADDING_PX = 16; // .cm-content padding (8px top + 8px bottom)
3131
3232
let lineCount = $derived(code.split('\n').length);
3333
let dialogHeight = $derived(() => {
3434
const lines = Math.min(lineCount, MAX_LINES);
35-
const contentHeight = lines * LINE_HEIGHT_PX + PADDING_PX;
36-
return contentHeight + HEADER_HEIGHT_PX;
35+
return Math.ceil(lines * LINE_HEIGHT_PX + CM_PADDING_PX + HEADER_HEIGHT_PX);
3736
});
3837
3938
// Subscribe to theme changes

src/lib/components/dialogs/ExportDialog.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@
4040
4141
// Line count for dynamic height
4242
const MAX_LINES = 35;
43-
const LINE_HEIGHT_PX = 20; // Approximate line height in CodeMirror
44-
const HEADER_HEIGHT_PX = 48; // Dialog header height
45-
const PADDING_PX = 16; // Vertical padding
43+
const LINE_HEIGHT_PX = 18.2; // CodeMirror default with 14px font
44+
const HEADER_HEIGHT_PX = 41; // Dialog header
45+
const CM_PADDING_PX = 16; // .cm-content padding (8px top + 8px bottom)
4646
4747
let lineCount = $derived(pythonCode.split('\n').length);
4848
let dialogHeight = $derived(() => {
4949
const lines = Math.min(lineCount, MAX_LINES);
50-
const contentHeight = lines * LINE_HEIGHT_PX + PADDING_PX;
51-
return contentHeight + HEADER_HEIGHT_PX;
50+
return Math.ceil(lines * LINE_HEIGHT_PX + CM_PADDING_PX + HEADER_HEIGHT_PX);
5251
});
5352
5453
// Handle dialog open/close

0 commit comments

Comments
 (0)