From 2e1809ec3363bb2c9acc19fc1d4aa1418078eb79 Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 28 Sep 2022 15:07:30 +0200 Subject: [PATCH] Fix key up behaviour in a multiline TextEditor A regression was introduced in d564e4931. Before that commit you could use key up to jump into position zero of a multiline TextEditor if the cursor was somewhere in the first line. Since that commit the keypress had no effect. This change restores the earlier behaviour. --- modules/juce_gui_basics/widgets/juce_TextEditor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index f04a84469b..d1e4a640ce 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -2036,7 +2036,13 @@ bool TextEditor::moveCaretUp (bool selecting) return moveCaretToStartOfLine (selecting); const auto caretPos = (getCaretRectangle() - getTextOffset()).toFloat(); - return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), caretPos.getY() - 1.0f), selecting); + + const auto newY = caretPos.getY() - 1.0f; + + if (newY < 0.0f) + return moveCaretToStartOfLine (selecting); + + return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), newY), selecting); } bool TextEditor::moveCaretDown (bool selecting)