Skip to content

Commit 1aa0465

Browse files
committed
Fix preview UI to render long single line SQLs correctly
1 parent 8e64aa5 commit 1aa0465

File tree

1 file changed

+23
-7
lines changed
  • core/trino-web-ui/src/main/resources/webapp-preview/src/components

1 file changed

+23
-7
lines changed

core/trino-web-ui/src/main/resources/webapp-preview/src/components/CodeBlock.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,28 @@ export const CodeBlock = (props: ICodeBlockProps) => {
5757
return
5858
}
5959

60-
const lineHeightOption = editor.getOption(monaco.editor.EditorOption.lineHeight)
61-
const lineHeight = typeof lineHeightOption === 'number' ? lineHeightOption : FALLBACK_LINE_HEIGHT_PX
62-
const lineCount = Math.max(code.split(LINE_BREAK_REGEX).length, 1)
63-
const estimatedHeight = lineCount * lineHeight + EDITOR_EXTRA_PADDING
64-
const viewportCap = window.innerHeight * VIEWPORT_HEIGHT_RATIO
65-
const clampedHeight = Math.min(estimatedHeight, viewportCap)
66-
setResolvedHeight(`${Math.round(clampedHeight)}px`)
60+
const estimateHeightFromLines = () => {
61+
const lineHeightOption = editor.getOption(monaco.editor.EditorOption.lineHeight)
62+
const lineHeight = typeof lineHeightOption === 'number' ? lineHeightOption : FALLBACK_LINE_HEIGHT_PX
63+
const lineCount = Math.max(code.split(LINE_BREAK_REGEX).length, 1)
64+
return lineCount * lineHeight + EDITOR_EXTRA_PADDING
65+
}
66+
67+
const updateHeight = (contentHeight?: number) => {
68+
const rawHeight =
69+
typeof contentHeight === 'number' ? contentHeight + EDITOR_EXTRA_PADDING : estimateHeightFromLines()
70+
const viewportCap = window.innerHeight * VIEWPORT_HEIGHT_RATIO
71+
const clampedHeight = Math.min(rawHeight, viewportCap)
72+
setResolvedHeight(`${Math.round(clampedHeight)}px`)
73+
}
74+
75+
updateHeight(editor.getContentHeight())
76+
77+
const disposable = editor.onDidContentSizeChange((event) => {
78+
updateHeight(event.contentHeight)
79+
})
80+
81+
editor.onDidDispose(() => disposable.dispose())
6782
}
6883

6984
const defaultMonacoOptions: MonacoEditor.IStandaloneEditorConstructionOptions = {
@@ -94,6 +109,7 @@ export const CodeBlock = (props: ICodeBlockProps) => {
94109
border: `1px solid ${theme.palette.mode === 'dark' ? '#3f3f3f' : '#ddd'}`,
95110
borderBottom: noBottomBorder ? 'none' : '',
96111
width: '100%',
112+
height: '100%',
97113
maxHeight: '90vh',
98114
})}
99115
>

0 commit comments

Comments
 (0)