@@ -169,18 +169,60 @@ export default function ObservabilityQueryLanguageComponent() {
169169
170170 const handleGlyphClick = useCallback ( ( lineNumber : number , isPlay : boolean ) => {
171171 const lines = queryRef . current . split ( '\n' ) ;
172- if ( lineNumber > 0 && lineNumber <= lines . length ) {
173- const newLines = [ ...lines ] ;
174- const line = newLines [ lineNumber - 1 ] ;
175- if ( isPlay ) {
176- newLines [ lineNumber - 1 ] = line . replace ( '|>' , '--|>' ) ;
172+
173+ const commentPattern = '-- ' ;
174+ const continuedCommentPattern = '--\\ ' ;
175+
176+ let pattern = '|>' ;
177+ let replacement = '--|>' ;
178+ let shouldComment = true ;
179+
180+ if ( ! isPlay ) {
181+ pattern = '--|>' ;
182+ replacement = '|>' ;
183+ shouldComment = false ;
184+ }
185+
186+ let currentLine = lineNumber - 1 ;
187+
188+ if ( lines [ currentLine ] . trim ( ) . startsWith ( pattern ) ) {
189+ lines [ currentLine ] = lines [ currentLine ] . replace ( pattern , replacement ) ;
190+ } else {
191+ console . log ( "No pipe found at line" , lineNumber ) ;
192+ return ;
193+ }
194+
195+ for ( let n = lineNumber ; n < lines . length ; n ++ ) {
196+ const line = lines [ n ] ;
197+
198+ if ( line . trim ( ) == "" ) {
199+ continue ;
200+ }
201+
202+ // stop when we hit the end of the pipe section
203+ if ( line . trim ( ) . startsWith ( "--|>" ) || line . trim ( ) . startsWith ( "|>" ) ) {
204+ break ;
205+ }
206+
207+ if ( shouldComment ) {
208+ if ( line . trim ( ) . startsWith ( continuedCommentPattern ) || line . trim ( ) . startsWith ( commentPattern ) ) {
209+ continue ;
210+ }
211+ lines [ n ] = continuedCommentPattern + line ;
177212 } else {
178- newLines [ lineNumber - 1 ] = line . replace ( '--|>' , '|>' ) ;
213+ if ( ! line . trim ( ) . startsWith ( continuedCommentPattern ) && ! line . trim ( ) . startsWith ( commentPattern ) ) {
214+ continue ;
215+ }
216+ lines [ n ] = line . replace ( continuedCommentPattern , "" ) ;
179217 }
180- setQuery ( newLines . join ( '\n' ) ) ;
181- setActiveQuery ( newLines . join ( '\n' ) ) ;
182218 }
183- } , [ ] ) ; // No need for dependencies since we're using ref
219+
220+ const newQuery = lines . join ( '\n' ) ;
221+
222+ setQuery ( newQuery ) ;
223+ setActiveQuery ( newQuery ) ;
224+
225+ } , [ ] ) ;
184226
185227
186228 const onFilterChange = useCallback ( ( columnName : string , value : string , operator : string ) => {
0 commit comments