### 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
size_slider->connect("value_changed", callable_mp(this, &GridMapEditor::_icon_size_changed));
	add_child(size_slider);
	EDITOR_DEF("editors/grid_map/preview_size", 64);
	mesh_library_palette = memnew(ItemList);
	add_child(mesh_library_palette);
	mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
	mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input));
	info_message = memnew(Label);
	info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes."));
	info_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
	info_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
	info_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
	info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
	info_message->set_anchors_and_offsets_preset(PRESET_FULL_RECT, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
	mesh_library_palette->add_child(info_message);
	edit_axis = Vector3::AXIS_Y;
	edit_floor[0] = -1;
	edit_floor[1] = -1;
	edit_floor[2] = -1;
	selection_mesh = RenderingServer::get_singleton()->mesh_create();
	paste_mesh = RenderingServer::get_singleton()->mesh_create();
	{
		
		Vector<Vector3> lines;
		Vector<Vector3> triangles;
		Vector<Vector3> square[3];
		for (int i = 0; i < 6; i++) {
			Vector3 face_points[4];
			for (int j = 0; j < 4; j++) {
				float v[3];