### Godot version

4.1.dev (a7276f1ce0)

### System information

MacOS 13.3 M1 Pro

### Issue description

when doing a Batch rename with two nodes being present in a `NodePath`. Batch Rename will try to update the `NodePath` but will fail which will results in this error
<img width="515" alt="Capture d’écran 2023-04-14 à 23 59 02" src="https://user-images.githubusercontent.com/66184050/232161972-57b49435-7707-4e41-bfed-613b073477b7.png">


### Steps to reproduce

1. Open the minimal reproduction project or follow the instruction below:
    1. first reproduce the following tree (this is because of #76069) <img width="235" alt="Capture d’écran 2023-04-14 à 23 09 47" src="https://user-images.githubusercontent.com/66184050/232155382-da3f9e22-26fb-4e10-bdcb-07cb60c25ea1.png">
    2. add a script to the root and export a `NodePath` variable
    3. Set the exported variable to the `GrandChild` node
4. select all node except the root.
5. Batch rename `C` to `T` for example
6. Inspect the root node. You should have a broken `NodePath` and an error.

### Minimal reproduction project

[test1.zip](https://github.com/godotengine/godot/files/11237175/test1.zip)
but_insert_root = memnew(Button);
	but_insert_root->set_text("ROOT");
	but_insert_root->set_tooltip_text(String("${ROOT}\n") + TTR("Root node name."));
	but_insert_root->set_focus_mode(Control::FOCUS_NONE);
	but_insert_root->connect("pressed", callable_mp(this, &RenameDialog::_insert_text).bind("${ROOT}"));
	but_insert_root->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	grd_substitute->add_child(but_insert_root);
	
	but_insert_count = memnew(Button);
	but_insert_count->set_text("COUNTER");
	but_insert_count->set_tooltip_text(String("${COUNTER}\n") + TTR("Sequential integer counter.\nCompare counter options."));
	but_insert_count->set_focus_mode(Control::FOCUS_NONE);
	but_insert_count->connect("pressed", callable_mp(this, &RenameDialog::_insert_text).bind("${COUNTER}"));
	but_insert_count->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	grd_substitute->add_child(but_insert_count);
	chk_per_level_counter = memnew(CheckBox);
	chk_per_level_counter->set_text(TTR("Per-level Counter"));
	chk_per_level_counter->set_tooltip_text(TTR("If set, the counter restarts for each group of child nodes."));
	vbc_substitute->add_child(chk_per_level_counter);
	HBoxContainer *hbc_count_options = memnew(HBoxContainer);
	vbc_substitute->add_child(hbc_count_options);
	Label *lbl_count_start = memnew(Label);
	lbl_count_start->set_text(TTR("Start"));
	lbl_count_start->set_tooltip_text(TTR("Initial value for the counter."));
	hbc_count_options->add_child(lbl_count_start);
	spn_count_start = memnew(SpinBox);
	spn_count_start->set_tooltip_text(TTR("Initial value for the counter."));
	spn_count_start->set_step(1);
	spn_count_start->set_min(0);
	hbc_count_options->add_child(spn_count_start);