File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
src/webviews/webview-side/selectInputSettings Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -60,13 +60,29 @@ export const SelectInputSettingsPanel: React.FC<ISelectInputSettingsPanelProps>
6060 } ;
6161
6262 const handleAddOption = ( ) => {
63- if ( newOption . trim ( ) ) {
64- setSettings ( ( prev ) => ( {
65- ...prev ,
66- options : [ ...prev . options , newOption . trim ( ) ]
67- } ) ) ;
68- setNewOption ( '' ) ;
63+ const trimmedValue = newOption . trim ( ) ;
64+
65+ // Check if the trimmed value is non-empty
66+ if ( ! trimmedValue ) {
67+ return ;
68+ }
69+
70+ // Normalize for comparison (case-insensitive)
71+ const normalizedValue = trimmedValue . toLowerCase ( ) ;
72+
73+ // Check if the normalized value is already present in options
74+ const isDuplicate = settings . options . some ( ( option ) => option . toLowerCase ( ) === normalizedValue ) ;
75+
76+ if ( isDuplicate ) {
77+ return ;
6978 }
79+
80+ // Add the trimmed value and clear input
81+ setSettings ( ( prev ) => ( {
82+ ...prev ,
83+ options : [ ...prev . options , trimmedValue ]
84+ } ) ) ;
85+ setNewOption ( '' ) ;
7086 } ;
7187
7288 const handleRemoveOption = ( index : number ) => {
You can’t perform that action at this time.
0 commit comments