@@ -19,18 +19,10 @@ import {
1919import { Textarea } from "@/components/ui/textarea" ;
2020import { Paragraph } from "@/components/ui/typography" ;
2121import { cn } from "@/lib/utils" ;
22+ import { detectLanguage , LANGUAGE_OPTIONS } from "@/utils/detectLanguage" ;
2223
2324import CodeEditor from "../CodeViewer/CodeEditor" ;
2425
25- const LANGUAGE_OPTIONS = [
26- { value : "plaintext" , label : "Plain Text" } ,
27- { value : "yaml" , label : "YAML" } ,
28- { value : "python" , label : "Python" } ,
29- { value : "javascript" , label : "JavaScript" } ,
30- { value : "json" , label : "JSON" } ,
31- { value : "sql" , label : "SQL" } ,
32- ] ;
33-
3426interface MultilineTextInputDialogProps {
3527 title : ReactNode ;
3628 description ?: string ;
@@ -57,7 +49,9 @@ export const MultilineTextInputDialog = ({
5749 onConfirm,
5850} : MultilineTextInputDialogProps ) => {
5951 const [ value , setValue ] = useState ( initialValue ) ;
60- const [ selectedLanguage , setSelectedLanguage ] = useState ( "plaintext" ) ;
52+ const [ selectedLanguage , setSelectedLanguage ] = useState ( ( ) =>
53+ detectLanguage ( initialValue ) ,
54+ ) ;
6155
6256 const handleConfirm = useCallback ( ( ) => {
6357 onConfirm ( value ) ;
@@ -83,8 +77,8 @@ export const MultilineTextInputDialog = ({
8377 } , [ initialValue ] ) ;
8478
8579 useEffect ( ( ) => {
86- setSelectedLanguage ( "plaintext" ) ;
87- } , [ highlightSyntax ] ) ;
80+ setSelectedLanguage ( detectLanguage ( initialValue ) ) ;
81+ } , [ initialValue ] ) ;
8882
8983 return (
9084 < Dialog open = { open } onOpenChange = { onCancel } >
@@ -112,7 +106,7 @@ export const MultilineTextInputDialog = ({
112106 </ Select >
113107 ) }
114108 </ InlineStack >
115- { highlightSyntax ? (
109+ { highlightSyntax && selectedLanguage !== "plaintext" ? (
116110 < div className = "h-64" >
117111 < CodeEditor
118112 value = { value }
@@ -133,15 +127,15 @@ export const MultilineTextInputDialog = ({
133127 ) }
134128 < DialogFooter >
135129 < InlineStack gap = "2" align = "space-between" className = "w-full" >
136- { ! highlightSyntax && maxLength && value . length >= maxLength && (
130+ { maxLength && value . length >= maxLength && (
137131 < Paragraph tone = "warning" size = "xs" >
138132 Maximum length { maxLength } characters
139133 </ Paragraph >
140134 ) }
141135 < InlineStack
142136 gap = "2"
143137 align = "end"
144- className = { cn ( ( highlightSyntax || ! maxLength ) && "w-full" ) }
138+ className = { cn ( ! maxLength && "w-full" ) }
145139 >
146140 < Button variant = "outline" onClick = { handleCancel } >
147141 Cancel
0 commit comments