### Godot version

v4.0.3.stable.mono.official [5222a99f5]

### System information

Windows 11

### Issue description

In the "Select a Node" windows, popped up when pressed the "Assign..." button of a `NodePath` property in the inspector.
Input any character in the "Filter Nodes" line, then clear it.

All ancestors of target type nodes become selectable.

I think it's because the correct result is supposed to be like this:
![image](https://github.com/godotengine/godot/assets/3178725/7d8ef6a2-d9f0-444e-8b18-0f251d553a1d)

but the invalid ancestors, which should be leaved in the dialog but set to unselectable, are in the wrong state.



### Steps to reproduce

- Create a new project.
- Create a new scene like this.
![image](https://github.com/godotengine/godot/assets/3178725/84acde89-a6a9-4ba7-adb4-f883531bd51a)
- Select `BoneAttachment3D` node, turn on `Use External Skeleton`
![image](https://github.com/godotengine/godot/assets/3178725/fd9fd252-253d-4a48-ba2b-764cef276738)
- Hit the "Assign..." button, open the dialog, it's good at this moment.
![image](https://github.com/godotengine/godot/assets/3178725/511d6fb8-4c83-408b-9717-0726cb7568ad)
- Input any character in the "Filter Nodes" line (like `d`).
![image](https://github.com/godotengine/godot/assets/3178725/cc60b4e4-c890-4c81-ae16-edc28fc18b57)



### Minimal reproduction project

N/A
selected = nullptr;
	can_rename = p_can_rename;
	can_open_instance = p_can_open_instance;
	editor_selection = nullptr;
	if (p_label) {
		Label *label = memnew(Label);
		label->set_theme_type_variation("HeaderSmall");
		label->set_position(Point2(10, 0));
		label->set_text(TTR("Scene Tree (Nodes):"));
		add_child(label);
	}
	tree = memnew(Tree);
	tree->set_anchor(SIDE_RIGHT, ANCHOR_END);
	tree->set_anchor(SIDE_BOTTOM, ANCHOR_END);
	tree->set_begin(Point2(0, p_label ? 18 : 0));
	tree->set_end(Point2(0, 0));
	tree->set_allow_reselect(true);
	tree->add_theme_constant_override("button_margin", 0);
	add_child(tree);
	SET_DRAG_FORWARDING_GCD(tree, SceneTreeEditor);