### 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
grid[i] = RID();
				RenderingServer::get_singleton()->free(selection_level_instance[i]);
			}
			RenderingServer::get_singleton()->free(selection_instance);
			RenderingServer::get_singleton()->free(paste_instance);
			selection_instance = RID();
			paste_instance = RID();
		} break;
		case NOTIFICATION_PROCESS: {
			if (!node) {
				return;
			}
			Transform3D xf = node->get_global_transform();
			if (xf != grid_xform) {
				for (int i = 0; i < 3; i++) {
					RS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
				}
				grid_xform = xf;
			}
			Ref<MeshLibrary> cgmt = node->get_mesh_library();
			if (cgmt.operator->() != last_mesh_library) {
				update_palette();
				
				_update_cursor_instance();
				update_grid();
			}
		} break;
		case NOTIFICATION_THEME_CHANGED: {
			_update_theme();
		} break;