Repository: godotengine/godot (language: cpp)

Issue:
LineEdit - Caret hides when focus is lost, even though Caret Force Displayed option is checked (Regression)
### Tested versions

Reproducible in v4.4.rc3.official

**Update:**
I've tested this on versions from 4.3stable on and the version where this stops working is in 4.4 dev3.  In 4.4 dev2 backwards, it works as intended.

### System information

Godot v4.4.rc3 - Windows 11 (build 26100) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 (NVIDIA; 32.0.15.7242) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 threads)

### Issue description

I'm using line input to edit text, and I'm moving away from the line with my controller to interact with other UI elements.  
I expect the blinking caret in the line Input to remain, since I have the caret_force_displayed property checked.

But it doesn't seem like this makes a different, and the caret goes away.

### Steps to reproduce

Open attached project and play it.

1) Type some text in the LineEdit node.
2) Click away or move away from the text with an attached controller.
3) Notce the caret goes away even though the caret_force_displayed property is checked.

### Minimal reproduction project (MRP)

[line_edit_caret_issue.zip](https://github.com/user-attachments/files/19038896/line_edit_caret_issue.zip)


Discussion / hints:
Does it stop working after 4.4.dev2?
correct.  from 4.4 dev3 on it no longer works.  
I believe this might be an intended consequence of this behavior change: #87674.

You can restore the previous behavior by enabling `keep_editing_on_text_submit`.
> You can restore the previous behavior by enabling `keep_editing_on_text_submit`.

No, it doesn't seem to always display the caret even with that option set. 
> No, it doesn't seem to always display the caret even with that option set.

Correct.  Even when `keep_editing_on_text_submit` is checked, the caret disappears when Focus is lost.  Basically the caret_forced_displayed property no longer works

![Image](https://github.com/user-attachments/assets/e9e920f7-09f5-4285-820c-261ea8048481)

.
Does input still work though (with that option enabled) even though the caret is invisible?
I can refocus the line_edit node with my controller using `ui_up`, `ui_down`, `ui_left` and `ui_right`.  And I can focus / unfocus the line_edit using the same commands on the controller. But in order for me to actually make the caret reappear, I need to click into the line_edit with my mouse. 
CC @KoBeWi 
> But in order for me to actually make the caret reappear, I need to click into the line_edit with my mouse.

You can also edit by pressing Enter. Which I think makes sense, because you can't input text with controller anyway.
LineEdit only accepts `ui_text_submit` from keyboard, this should be easy to fix. You can also connect `focus_entered` to `edit`, to edit the LineEdit immediately.
In my use case, there is no keyboard to press Enter on.  I'm trying to edit a line of text remotely by using a controller only.  This requires that I leave the focus of the line edit and interact with other UI elements (Buttons, primarily) to feed in specific string combinations to LineEdit.  

The functionality of `carat_force_displayed` becomes essential in this situation.  When it was working, I could see where the letters would appear on the LineEdit node without having to refocus on the LineEdit to see the caret.

Fix patch:
diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml
index c6cdacb6ec25..879b179dbfef 100644
--- a/doc/classes/LineEdit.xml
+++ b/doc/classes/LineEdit.xml
@@ -252,7 +252,7 @@
 			The caret's column position inside the [LineEdit]. When set, the text may scroll to accommodate it.
 		</member>
 		<member name="caret_force_displayed" type="bool" setter="set_caret_force_displayed" getter="is_caret_force_displayed" default="false">
-			If [code]true[/code], the [LineEdit] will always show the caret, even if focus is lost.
+			If [code]true[/code], the [LineEdit] will always show the caret, even if not editing or focus is lost.
 		</member>
 		<member name="caret_mid_grapheme" type="bool" setter="set_caret_mid_grapheme_enabled" getter="is_caret_mid_grapheme_enabled" default="false">
 			Allow moving caret, selecting and removing the individual composite character components.
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 969e2fd3a35c..f4d66d5a281d 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -1733,7 +1733,7 @@ void LineEdit::_validate_caret_can_draw() {
 		draw_caret = true;
 		caret_blink_timer = 0.0;
 	}
-	caret_can_draw = editing && (window_has_focus || (menu && menu->has_focus())) && (has_focus() || caret_force_displayed);
+	caret_can_draw = (caret_force_displayed && !is_part_of_edited_scene()) || (editing && (window_has_focus || (menu && menu->has_focus())) && has_focus());
 }
 
 void LineEdit::delete_char() {


Test patch: