### 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 (p_can_rename) {
		tree->set_allow_rmb_select(true);
		tree->connect("item_mouse_selected", callable_mp(this, &SceneTreeEditor::_rmb_select));
		tree->connect("empty_clicked", callable_mp(this, &SceneTreeEditor::_empty_clicked));
	}
	tree->connect("cell_selected", callable_mp(this, &SceneTreeEditor::_selected_changed));
	tree->connect("item_edited", callable_mp(this, &SceneTreeEditor::_renamed));
	tree->connect("multi_selected", callable_mp(this, &SceneTreeEditor::_cell_multi_selected));
	tree->connect("button_clicked", callable_mp(this, &SceneTreeEditor::_cell_button_pressed));
	tree->connect("nothing_selected", callable_mp(this, &SceneTreeEditor::_deselect_items));
	error = memnew(AcceptDialog);
	add_child(error);
	warning = memnew(AcceptDialog);
	add_child(warning);
	warning->set_title(TTR("Node Configuration Warning!"));
	last_hash = 0;
	blocked = 0;
	update_timer = memnew(Timer);
	update_timer->connect("timeout", callable_mp(this, &SceneTreeEditor::_update_tree).bind(false));
	update_timer->set_one_shot(true);
	update_timer->set_wait_time(0.5);
	add_child(update_timer);
	script_types = memnew(List<StringName>);
	ClassDB::get_inheriters_from_class("Script", script_types);
}
SceneTreeEditor::~SceneTreeEditor() {
	memdelete(script_types);
}
/******** DIALOG *********/
void SceneTreeDialog::popup_scenetree_dialog() {