Skip to content

Commit ce98a55

Browse files
committed
Fix preview UI to render long single line SQLs in larger code block
1 parent 75f6648 commit ce98a55

File tree

1 file changed

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

1 file changed

+22
-7
lines changed

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

Lines changed: 22 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 = {

0 commit comments

Comments
 (0)