### Godot version

master ([06ccbfe](https://github.com/godotengine/godot/commit/06ccbfe8eec6e840db3df2360dc2804386f940b8))

### System information

PopOS 22.04

### Issue description

Sometimes the doc page is broken when the engine is closed and then restarted.
Closing the doc and opening it again fixes it.

![2023-05-27_22-15](https://github.com/godotengine/godot/assets/3624853/ed202a55-03e8-420a-bc1c-ccfc7f7cd02a)


### Steps to reproduce

- Open a documentation page for any node
- Restart Godot

### Minimal reproduction project

NA

EDIT : Added the commit hash @Calinou 
ERR_FAIL_COND_V(!selection.enabled, false);
	if (p_string.size() == 0) {
		selection.active = false;
		return false;
	}
	int char_idx = p_search_previous ? -1 : 0;
	int current_line = 0;
	int to_line = main->first_invalid_line.load();
	int ending_line = to_line - 1;
	if (p_from_selection && selection.active) {
		
		char_idx = p_search_previous ? selection.from_char - 1 : selection.to_char;