From d564e49312f7c4dd34b3cb20479c9f54172f04ca Mon Sep 17 00:00:00 2001 From: attila Date: Mon, 12 Sep 2022 19:39:38 +0200 Subject: [PATCH] TextEditor: Change caret positioning when clicking before text and between lines This commit fixes an issue when using large lineSpacing, where the caret would jump to the end of the previous line when clicking between lines. With the new behaviour the line spacing is considered to belong to the previous line. The commit also changes the behaviour observed when clicking in the empty space before the first line. Until now the caret would jump into the first character position. Now it behaves as if the space before the first line would belong to the first line. --- modules/juce_gui_basics/widgets/juce_TextEditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 10a09d3a64..f04a84469b 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -2614,9 +2614,9 @@ int TextEditor::indexAtPosition (const float x, const float y) const { for (Iterator i (*this); i.next();) { - if (y < i.lineY + i.lineHeight) + if (y < i.lineY + (i.lineHeight * lineSpacing)) { - if (y < i.lineY) + if (jmax (0.0f, y) < i.lineY) return jmax (0, i.indexInText - 1); if (x <= i.atomX || i.atom->isNewLine())