### 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
selection.active = p_active;
	selection.begin = p_begin;
	selection.end = p_end;
	selection.click = p_begin;
	selection.current = p_end;
	if (is_visible_in_tree()) {
		_update_selection_transform();
	}
	options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_CLEAR), !selection.active);
	options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_CUT), !selection.active);
	options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_DUPLICATE), !selection.active);
	options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_FILL), !selection.active);
}
bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click) {
	if (!spatial_editor) {
		return false;
	}
	if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
		return false;
	}
	Ref<MeshLibrary> mesh_library = node->get_mesh_library();
	if (mesh_library.is_null()) {
		return false;
	}
	if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) {
		return false;