@@ -4,12 +4,36 @@ import InputNonDraggable from "../InputNonDraggable";
44import NeoType from "./NeoType" ;
55
66type Props = {
7- arg ?: string | number ;
7+ arg ?: any ;
88 autoSuggestListId : string ;
99 isReadOnly : boolean ;
1010 name : string ;
1111 type ?: string | number ;
12- onUpdate : ( newArgument : string | number ) => void ;
12+ onUpdate : ( newArgument : any ) => void ;
13+ } ;
14+
15+ const valueToString = ( value : any ) => {
16+ if ( ! value ) {
17+ return "" ;
18+ } else if ( Array . isArray ( value ) || typeof value === "object" ) {
19+ return JSON . stringify ( value ) ;
20+ } else {
21+ return `${ value } ` ;
22+ }
23+ } ;
24+
25+ const stringToValue = ( text : string ) => {
26+ if ( `${ parseInt ( text ) } ` === text ) {
27+ return parseInt ( text ) ;
28+ } else if ( `${ parseFloat ( text ) } ` === text ) {
29+ return parseFloat ( text ) ;
30+ } else {
31+ try {
32+ return JSON . parse ( text ) ;
33+ } catch ( e ) {
34+ return `${ text } ` ;
35+ }
36+ }
1337} ;
1438
1539export default function ArgumentInput ( {
@@ -20,7 +44,7 @@ export default function ArgumentInput({
2044 type,
2145 onUpdate,
2246} : Props ) {
23- const [ value , setValue ] = useState ( ` ${ arg || "" } ` ) ;
47+ const [ value , setValue ] = useState ( valueToString ( arg ) ) ;
2448 const inputStyle : React . CSSProperties = {
2549 color : "var(--vscode-input-foreground)" ,
2650 backgroundColor : "var(--vscode-input-background)" ,
@@ -31,15 +55,6 @@ export default function ArgumentInput({
3155 padding : 1 ,
3256 marginLeft : 15 ,
3357 } ;
34- const coerceType = ( text : string ) => {
35- if ( `${ parseInt ( text ) } ` === text ) {
36- return parseInt ( text ) ;
37- } else if ( `${ parseFloat ( text ) } ` === text ) {
38- return parseFloat ( text ) ;
39- } else {
40- return `${ text } ` ;
41- }
42- } ;
4358 return (
4459 < div style = { { marginLeft : 15 , marginTop : 4 } } >
4560 < div >
@@ -57,12 +72,12 @@ export default function ArgumentInput({
5772 style = { inputStyle }
5873 type = "text"
5974 value = { value }
60- onBlur = { ( e ) => onUpdate ( coerceType ( e . target . value ) ) }
61- onChange = { ( e ) => setValue ( e . target . value ) }
75+ onBlur = { ( e ) => onUpdate ( stringToValue ( e . target . value ) ) }
76+ onChange = { ( e ) => setValue ( valueToString ( e . target . value ) ) }
6277 onKeyDown = { ( e ) => {
6378 if ( e . metaKey ) {
6479 // User may be about to save
65- onUpdate ( coerceType ( value ) ) ;
80+ onUpdate ( stringToValue ( value ) ) ;
6681 }
6782 } }
6883 />
0 commit comments