@@ -15,6 +15,7 @@ const EditorWrapper = styled.div<{ $noBorder?: boolean }>`
1515 border: ${ ( { $noBorder, theme } ) =>
1616 $noBorder ? "none" : `1px solid ${ theme . color . selection } ` } ;
1717 background: ${ ( { theme } ) => theme . color . backgroundDarker } ;
18+ overflow: hidden;
1819
1920 .monaco-editor-background {
2021 background: ${ ( { theme } ) => theme . color . backgroundDarker } ;
@@ -103,41 +104,40 @@ const CopyButtonFloating = styled(CopyButtonBase)`
103104`
104105
105106type BaseLiteEditorProps = {
106- height ?: string | number
107107 language ?: string
108108 theme ?: string
109109 fontSize ?: number
110110 padding ?: { top ?: number ; bottom ?: number }
111111 lineHeight ?: number
112- noBorder ?: boolean
112+ maxHeight : number
113113}
114114
115115type RegularEditorProps = BaseLiteEditorProps & {
116116 diffEditor ?: false
117117 value : string
118118 original ?: never
119119 modified ?: never
120+ onOpenInEditor : ( value : string ) => void
120121}
121122
122123type DiffEditorProps = BaseLiteEditorProps & {
123124 diffEditor : true
124125 original : string
125126 modified : string
126127 value ?: never
127- onExpandDiff ? : ( ) => void
128+ onOpenInEditor : ( original : string , modified : string ) => void
128129}
129130
130131type LiteEditorProps = RegularEditorProps | DiffEditorProps
131132
132133export const LiteEditor : React . FC < LiteEditorProps > = React . memo (
133134 ( {
134- height = "100%" ,
135135 language = QuestDBLanguageName ,
136136 theme = "dracula" ,
137137 fontSize = 12 ,
138138 padding = { top : 8 , bottom : 8 } ,
139139 lineHeight = 20 ,
140- noBorder ,
140+ maxHeight ,
141141 ...props
142142 } ) => {
143143 const appTheme = useTheme ( )
@@ -149,30 +149,36 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
149149 setTimeout ( ( ) => setCopied ( false ) , 2000 )
150150 }
151151
152+ const getContentHeight = ( content : string ) => {
153+ const lineCount = content . split ( "\n" ) . length
154+ return lineCount * lineHeight + ( props . diffEditor ? 0 : 16 )
155+ }
156+
152157 if ( props . diffEditor ) {
153158 return (
154159 < EditorWrapper
155- $noBorder = { noBorder }
160+ $noBorder
156161 style = { {
157- height,
158- ...( ! noBorder ? { paddingTop : 8 , paddingBottom : 8 } : undefined ) ,
162+ height : maxHeight ,
163+ paddingTop : 8 ,
164+ paddingBottom : 8 ,
159165 } }
160166 >
161167 < ButtonsContainer >
162- { props . onExpandDiff && (
163- < OpenInEditorButton
164- className = "open-in-editor-btn"
165- onClick = { props . onExpandDiff }
166- title = "Open in editor"
167- data-hook = "diff-open-in- editor-button "
168- >
169- Open in editor
170- < SquareSplitHorizontalIcon
171- size = "1.8rem"
172- color = { appTheme . color . offWhite }
173- />
174- </ OpenInEditorButton >
175- ) }
168+ < OpenInEditorButton
169+ className = "open-in-editor-btn"
170+ onClick = { ( ) =>
171+ props . onOpenInEditor ( props . original , props . modified )
172+ }
173+ title = "Open in editor"
174+ data-hook = "diff-open-in-editor-button"
175+ >
176+ Open in editor
177+ < SquareSplitHorizontalIcon
178+ size = "1.8rem"
179+ color = { appTheme . color . offWhite }
180+ / >
181+ </ OpenInEditorButton >
176182 < CopyButtonBase
177183 skin = "transparent"
178184 onClick = { ( ) => handleCopy ( props . modified ) }
@@ -183,7 +189,7 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
183189 </ CopyButtonBase >
184190 </ ButtonsContainer >
185191 < DiffEditor
186- height = { height }
192+ height = { maxHeight }
187193 language = { language }
188194 original = { props . original }
189195 modified = { props . modified }
@@ -208,6 +214,8 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
208214 scrollbar : {
209215 vertical : "hidden" ,
210216 horizontal : "hidden" ,
217+ alwaysConsumeMouseWheel : false ,
218+ handleMouseWheel : false ,
211219 } ,
212220 automaticLayout : true ,
213221 folding : false ,
@@ -228,18 +236,49 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
228236 )
229237 }
230238
239+ const contentHeight = getContentHeight ( props . value )
240+ const effectiveHeight = maxHeight
241+ ? Math . min ( contentHeight , maxHeight )
242+ : contentHeight
243+ const showOpenInEditor = contentHeight > maxHeight
244+
231245 return (
232- < EditorWrapper $noBorder = { noBorder } style = { { height } } >
233- < CopyButtonFloating
234- skin = "transparent"
235- onClick = { ( ) => handleCopy ( props . value ?? "" ) }
236- title = "Copy to clipboard"
237- >
238- { copied && < SuccessIcon size = "1rem" /> }
239- < FileCopy size = "1.8rem" />
240- </ CopyButtonFloating >
246+ < EditorWrapper style = { { height : effectiveHeight } } >
247+ { showOpenInEditor ? (
248+ < ButtonsContainer >
249+ < OpenInEditorButton
250+ className = "open-in-editor-btn"
251+ onClick = { ( ) => props . onOpenInEditor ( props . value ) }
252+ title = "Open in editor"
253+ data-hook = "code-open-in-editor-button"
254+ >
255+ Open in editor
256+ < SquareSplitHorizontalIcon
257+ size = "1.8rem"
258+ color = { appTheme . color . offWhite }
259+ />
260+ </ OpenInEditorButton >
261+ < CopyButtonBase
262+ skin = "transparent"
263+ onClick = { ( ) => handleCopy ( props . value ?? "" ) }
264+ title = "Copy to clipboard"
265+ >
266+ { copied && < SuccessIcon size = "1rem" /> }
267+ < FileCopy size = "1.8rem" />
268+ </ CopyButtonBase >
269+ </ ButtonsContainer >
270+ ) : (
271+ < CopyButtonFloating
272+ skin = "transparent"
273+ onClick = { ( ) => handleCopy ( props . value ?? "" ) }
274+ title = "Copy to clipboard"
275+ >
276+ { copied && < SuccessIcon size = "1rem" /> }
277+ < FileCopy size = "1.8rem" />
278+ </ CopyButtonFloating >
279+ ) }
241280 < Editor
242- height = { height }
281+ height = { effectiveHeight }
243282 language = { language }
244283 value = { props . value }
245284 theme = { theme }
@@ -259,9 +298,12 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
259298 scrollbar : {
260299 vertical : "hidden" ,
261300 horizontal : "hidden" ,
301+ alwaysConsumeMouseWheel : false ,
302+ handleMouseWheel : false ,
262303 } ,
263304 fontSize,
264305 padding,
306+ lineHeight,
265307 } }
266308 />
267309 </ EditorWrapper >
@@ -272,7 +314,9 @@ export const LiteEditor: React.FC<LiteEditorProps> = React.memo(
272314 prevProps . value === nextProps . value &&
273315 prevProps . diffEditor === nextProps . diffEditor &&
274316 prevProps . original === nextProps . original &&
275- prevProps . modified === nextProps . modified
317+ prevProps . modified === nextProps . modified &&
318+ prevProps . maxHeight === nextProps . maxHeight &&
319+ prevProps . onOpenInEditor === nextProps . onOpenInEditor
276320 )
277321 } ,
278322)
0 commit comments