Skip to content

Commit 4eb8c0f

Browse files
committed
ParameterInput: Add current value to options list
If the current value is not already in the options list, add it to the list. https://phabricator.endlessm.com/T35564
1 parent e0052d8 commit 4eb8c0f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,18 @@ func _update_option_input(current_value: Variant = null):
240240
if item == current_value:
241241
selected_item_index = item_index
242242

243-
if _option_input.item_count == 0:
243+
if selected_item_index == -1 and current_value:
244+
# If the current value is not in the default list of options, add it
245+
# and select it.
246+
if _option_input.item_count > 0:
247+
_option_input.add_separator()
248+
var item_index = _option_input.item_count
249+
var option_label = current_value.capitalize() if current_value is String else str(current_value)
250+
_option_input.add_item(option_label)
251+
_option_input.set_item_tooltip(item_index, current_value)
252+
_option_input.set_item_metadata(item_index, current_value)
253+
selected_item_index = item_index
254+
elif _option_input.item_count == 0:
244255
var item_index = _option_input.item_count
245256
_option_input.add_item("<%s>" % placeholder)
246257
_option_input.set_item_disabled(item_index, true)

0 commit comments

Comments
 (0)