### Godot version

v4.0.beta.custom_build [13f0158]

### System information

Windows 10

### Issue description

When doing operations (`begin_complex_operation` and `end_complex_operation`) with multiple selections in TextEdit, some of these selections don't revert upon undo. This behavior is affects some of script editor's operations, like duplicate selection and delete lines.

### Steps to reproduce

Open script editor, make multiple selections. Keep in mind what you have selected. Do duplicate selection (ctrl+shift+D). Undo (ctrl+Z). Compare the result to what you remember.

### Minimal reproduction project

N/A
break;
						}
					}
					const String &str = wrap_rows[line_wrap_index];
					int char_margin = xmargin_beg - first_visible_col;
					int ofs_x = 0;
					int ofs_y = 0;
					if (!editable) {
						ofs_x = theme_cache.style_readonly->get_offset().x / 2;
						ofs_x -= theme_cache.style_normal->get_offset().x / 2;
						ofs_y = theme_cache.style_readonly->get_offset().y / 2;
					} else {
						ofs_y = theme_cache.style_normal->get_offset().y / 2;
					}
					ofs_y += i * row_height + theme_cache.line_spacing / 2;
					ofs_y -= first_visible_line_wrap_ofs * row_height;
					ofs_y -= _get_v_scroll_offset() * row_height;
					bool clipped = false;
					if (ofs_y + row_height < top_limit_y) {
						
						
						clipped = true;
					}
					if (ofs_y > bottom_limit_y) {
						
						i = draw_amount;
						break;
					}
					if (text.get_line_background_color(line) != Color(0, 0, 0, 0)) {
						if (rtl) {