### 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
switch (p_option) {
		case MENU_OPTION_PREV_LEVEL: {
			floor->set_value(floor->get_value() - 1);
		} break;
		case MENU_OPTION_NEXT_LEVEL: {
			floor->set_value(floor->get_value() + 1);
		} break;
		case MENU_OPTION_X_AXIS:
		case MENU_OPTION_Y_AXIS:
		case MENU_OPTION_Z_AXIS: {
			int new_axis = p_option - MENU_OPTION_X_AXIS;
			for (int i = 0; i < 3; i++) {
				int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i);
				options->get_popup()->set_item_checked(idx, i == new_axis);
			}
			if (edit_axis != new_axis) {
				int item1 = options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL);
				int item2 = options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL);
				if (edit_axis == Vector3::AXIS_Y) {
					options->get_popup()->set_item_text(item1, TTR("Next Plane"));
					options->get_popup()->set_item_text(item2, TTR("Previous Plane"));
					spin_box_label->set_text(TTR("Plane:"));
				} else if (new_axis == Vector3::AXIS_Y) {
					options->get_popup()->set_item_text(item1, TTR("Next Floor"));
					options->get_popup()->set_item_text(item2, TTR("Previous Floor"));
					spin_box_label->set_text(TTR("Floor:"));
				}
			}
			edit_axis = Vector3::Axis(new_axis);