### 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
il.sort();
	String filter = search_box->get_text().strip_edges();
	int item = 0;
	for (_CGMEItemSort &E : il) {
		int id = E.id;
		String name = mesh_library->get_item_name(id);
		Ref<Texture2D> preview = mesh_library->get_item_preview(id);
		if (name.is_empty()) {
			name = "#" + itos(id);
		}
		if (!filter.is_empty() && !filter.is_subsequence_ofn(name)) {
			continue;
		}
		mesh_library_palette->add_item("");
		if (!preview.is_null()) {
			mesh_library_palette->set_item_icon(item, preview);
			mesh_library_palette->set_item_tooltip(item, name);
		}
		mesh_library_palette->set_item_text(item, name);
		mesh_library_palette->set_item_metadata(item, id);
		item++;
	}
	if (selected != -1 && mesh_library_palette->get_item_count() > 0) {
		
		selected_palette = MIN(selected, mesh_library_palette->get_item_count() - 1);
		mesh_library_palette->select(selected_palette);
	}
	last_mesh_library = *mesh_library;
}
void GridMapEditor::edit(GridMap *p_gridmap) {