### Godot version

4.0 Beta 10

### System information

Windows 10

### Issue description

when picking tiles from a gridmap and you have a search filter applied, it often doesn't do anything, instead I get an index out of bounds error in the console
`scene/gui/item_list.cpp:424 - Index p_current = 8 is out of bounds (items.size() = 4).`

### Steps to reproduce

1. Open a project using a gridmap like the platformer demo, or create one.
2. Search for specific tiles inside the tile selection.
3. Try to pick a tile inside the 3D viewport with that you want to paint (maybe you don't want to reset the filter and do a long search there)

In some cases it works, but mostly it doesn't work (depending on the tile you picked and what you searched for)
Also I am not sure, but I have the feeling that in a few cases it picks the wrong tile, instead of throwing an error

### Minimal reproduction project

Any project that uses a gridmap, for example the platformer demo from the demo projects repo
settings_pick_distance->set_value(EDITOR_GET("editors/grid_map/pick_distance"));
	settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
	options->get_popup()->connect("id_pressed", callable_mp(this, &GridMapEditor::_menu_option));
	HBoxContainer *hb = memnew(HBoxContainer);
	add_child(hb);
	hb->set_h_size_flags(SIZE_EXPAND_FILL);
	search_box = memnew(LineEdit);
	search_box->set_h_size_flags(SIZE_EXPAND_FILL);
	search_box->set_placeholder(TTR("Filter Meshes"));
	hb->add_child(search_box);
	search_box->connect("text_changed", callable_mp(this, &GridMapEditor::_text_changed));
	search_box->connect("gui_input", callable_mp(this, &GridMapEditor::_sbox_input));
	mode_thumbnail = memnew(Button);
	mode_thumbnail->set_flat(true);
	mode_thumbnail->set_toggle_mode(true);
	mode_thumbnail->set_pressed(true);
	hb->add_child(mode_thumbnail);
	mode_thumbnail->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode).bind(DISPLAY_THUMBNAIL));
	mode_list = memnew(Button);
	mode_list->set_flat(true);
	mode_list->set_toggle_mode(true);
	mode_list->set_pressed(false);
	hb->add_child(mode_list);
	mode_list->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode).bind(DISPLAY_LIST));
	size_slider = memnew(HSlider);
	size_slider->set_h_size_flags(SIZE_EXPAND_FILL);
	size_slider->set_min(0.2f);
	size_slider->set_max(4.0f);
	size_slider->set_step(0.1f);
	size_slider->set_value(1.0f);