### 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
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
			item->set_selectable(0, false);
		}
	}
}
void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
	if (!p_node || (p_node != get_scene_node() && !p_node->get_owner())) {
		return;
	}
	TreeItem *item = _find(tree->get_root(), p_node->get_path());
	if (!item) {
		return;
	}
	int idx = item->get_button_by_id(0, BUTTON_VISIBILITY);
	ERR_FAIL_COND(idx == -1);
	bool node_visible = false;
	if (p_node->is_class("CanvasItem") || p_node->is_class("CanvasLayer") || p_node->is_class("Window")) {
		node_visible = p_node->call("is_visible");
		CanvasItemEditor::get_singleton()->get_viewport_control()->queue_redraw();
	} else if (p_node->is_class("Node3D")) {
		node_visible = p_node->call("is_visible");
	}
	if (node_visible) {
		item->set_button(0, idx, get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")));
	} else {
		item->set_button(0, idx, get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")));
	}
	_update_visibility_color(p_node, item);
}
void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) {