From 361b29edb6d4686da5be609ddc0d4484618e7b09 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 20 May 2021 17:56:49 +0100 Subject: [PATCH] Offset TextEditor::getTextBounds() by viewport position --- modules/juce_gui_basics/widgets/juce_TextEditor.cpp | 4 +++- modules/juce_gui_basics/widgets/juce_TextEditor.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index c36fced547..387e283e70 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -1498,7 +1498,9 @@ RectangleList TextEditor::getTextBounds (Range textRange) } } - boundingBox.offsetAll (getLeftIndent(), roundToInt ((float) getTopIndent() + yOffset)); + boundingBox.offsetAll (getLeftIndent() - viewport->getViewPositionX(), + roundToInt ((float) getTopIndent() + yOffset) - viewport->getViewPositionY()); + return boundingBox; } diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.h b/modules/juce_gui_basics/widgets/juce_TextEditor.h index 2aaec63a9a..5e973d3adf 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.h +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.h @@ -537,6 +537,9 @@ public: /** Returns the bounding box for a range of text in the editor. As the range may span multiple lines, this method returns a RectangleList. + + The bounds are relative to the component's top-left and may extend beyond the bounds + of the component if the text is long and word wrapping is disabled. */ RectangleList getTextBounds (Range textRange);