### 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
if (!scr.is_null()) {
			String additional_notes;
			Color button_color = Color(1, 1, 1);
			// C
			if (scr->is_tool()) {
				additional_notes += "\n" + TTR("This script is currently running in the editor.");
				button_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
			}
			if (EditorNode::get_singleton()->get_object_custom_type_base(p_node) == scr) {
				additional_notes += "\n" + TTR("This script is a custom type.");
				button_color.a = 0.5;
			}
			item->add_button(0, get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), BUTTON_SCRIPT, false, TTR("Open Script:") + " " + scr->get_path() + additional_notes);
			item->set_button_color(0, item->get_button_count(0) - 1, button_color);
		}
		if (p_node->is_class("CanvasItem")) {
			if (p_node->has_meta("_edit_lock_")) {
				item->add_button(0, get_theme_icon(SNAME("Lock"), SNAME("EditorIcons")), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
			}
			if (p_node->has_meta("_edit_group_")) {
				item->add_button(0, get_theme_icon(SNAME("Group"), SNAME("EditorIcons")), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make them selectable."));
			}
			bool v = p_node->call("is_visible");
			if (v) {
				item->add_button(0, get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
			} else {
				item->add_button(0, get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
			}
			if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
				p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed).bind(p_node));