@@ -334,7 +334,8 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
334334 case JsonValueKind . String :
335335 {
336336 elementCount ++ ;
337- var text = $ "{ name } : \" { el . GetString ( ) } \" ";
337+ var stringValue = el . GetString ( ) ?? string . Empty ;
338+ var text = $ "{ name } : \" { stringValue } \" ";
338339 var tb = new TextBox
339340 {
340341 Text = text ,
@@ -354,13 +355,14 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
354355 {
355356 try
356357 {
357- var colonIndex = text . IndexOf ( ':' ) ;
358+ var currentText = textBox . Text ;
359+ var colonIndex = currentText . IndexOf ( ':' ) ;
358360 if ( colonIndex >= 0 )
359361 {
360- var firstQuote = text . IndexOf ( '"' , colonIndex ) ;
362+ var firstQuote = currentText . IndexOf ( '"' , colonIndex ) ;
361363 if ( firstQuote >= 0 )
362364 {
363- var lastQuote = text . LastIndexOf ( '"' ) ;
365+ var lastQuote = currentText . LastIndexOf ( '"' ) ;
364366 if ( lastQuote > firstQuote )
365367 {
366368 textBox . Select ( firstQuote + 1 , lastQuote - firstQuote - 1 ) ;
@@ -389,6 +391,7 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
389391 IsReadOnly = true ,
390392 BorderThickness = new Thickness ( 0 ) ,
391393 Background = System . Windows . Media . Brushes . Transparent ,
394+ TextWrapping = TextWrapping . Wrap ,
392395 Margin = new Thickness ( 4 , 2 , 0 , 2 ) ,
393396 FontFamily = new System . Windows . Media . FontFamily ( "Consolas" ) ,
394397 CaretBrush = System . Windows . Media . Brushes . Transparent ,
@@ -401,11 +404,17 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
401404 {
402405 try
403406 {
404- var colonIndex = text . IndexOf ( ':' ) ;
405- if ( colonIndex >= 0 && colonIndex < text . Length - 1 )
407+ var currentText = textBox . Text ;
408+ var colonIndex = currentText . IndexOf ( ':' ) ;
409+ if ( colonIndex >= 0 && colonIndex < currentText . Length - 1 )
406410 {
407411 var valueStart = colonIndex + 1 ;
408- textBox . Select ( valueStart , text . Length - valueStart ) ;
412+ // Trim leading spaces
413+ while ( valueStart < currentText . Length && currentText [ valueStart ] == ' ' )
414+ {
415+ valueStart ++ ;
416+ }
417+ textBox . Select ( valueStart , currentText . Length - valueStart ) ;
409418 }
410419 }
411420 catch
@@ -426,6 +435,7 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
426435 IsReadOnly = true ,
427436 BorderThickness = new Thickness ( 0 ) ,
428437 Background = System . Windows . Media . Brushes . Transparent ,
438+ TextWrapping = TextWrapping . Wrap ,
429439 Margin = new Thickness ( 4 , 2 , 0 , 2 ) ,
430440 FontFamily = new System . Windows . Media . FontFamily ( "Consolas" ) ,
431441 CaretBrush = System . Windows . Media . Brushes . Transparent ,
@@ -438,11 +448,17 @@ private UIElement CreateVisualForElement(string name, JsonElement el, ref int el
438448 {
439449 try
440450 {
441- var colonIndex = text . IndexOf ( ':' ) ;
442- if ( colonIndex >= 0 && colonIndex < text . Length - 1 )
451+ var currentText = textBox2 . Text ;
452+ var colonIndex = currentText . IndexOf ( ':' ) ;
453+ if ( colonIndex >= 0 && colonIndex < currentText . Length - 1 )
443454 {
444455 var valueStart = colonIndex + 1 ;
445- textBox2 . Select ( valueStart , text . Length - valueStart ) ;
456+ // Trim leading spaces
457+ while ( valueStart < currentText . Length && currentText [ valueStart ] == ' ' )
458+ {
459+ valueStart ++ ;
460+ }
461+ textBox2 . Select ( valueStart , currentText . Length - valueStart ) ;
446462 }
447463 }
448464 catch
@@ -474,7 +490,11 @@ private void AddContextMenu(TextBox tb)
474490 {
475491 var contextMenu = new ContextMenu ( ) ;
476492 var copyItem = new MenuItem { Header = Strings . Copy } ;
477- copyItem . Click += ( s , e ) => ClipboardHelper . CopyWithFeedback ( tb . Text , null ) ;
493+ copyItem . Click += ( s , e ) =>
494+ {
495+ var textToCopy = ! string . IsNullOrEmpty ( tb . SelectedText ) ? tb . SelectedText : tb . Text ;
496+ ClipboardHelper . CopyWithFeedback ( textToCopy , null ) ;
497+ } ;
478498 contextMenu . Items . Add ( copyItem ) ;
479499 tb . ContextMenu = contextMenu ;
480500 }
0 commit comments