Skip to content

Commit 6a53ddc

Browse files
committed
TextEditor: Restore JUCE 7 behaviour for the first line's alignment when line spacing > 1
1 parent 56b7b76 commit 6a53ddc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

modules/juce_gui_basics/widgets/juce_TextEditor.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,24 @@ float TextEditor::getYOffset() const
817817
{
818818
const auto bottomY = getMaximumTextHeight();
819819

820+
const auto juce7LineSpacingOffset = std::invoke ([&]
821+
{
822+
if (approximatelyEqual (lineSpacing, 1.0f) || textStorage->isEmpty())
823+
return 0.0f;
824+
825+
const auto& lineMetrics = textStorage->front().value->getShapedText().getLineMetricsForGlyphRange();
826+
827+
if (lineMetrics.isEmpty())
828+
return 0.0f;
829+
830+
const auto& line = lineMetrics.front().value;
831+
832+
jassert (lineSpacing >= 1.0f);
833+
return line.maxAscent * (1.0f / lineSpacing - 1.0f);
834+
});
835+
820836
if (justification.testFlags (Justification::top) || isTextStorageHeightGreaterEqualThan ((float) bottomY))
821-
return 0;
837+
return juce7LineSpacingOffset;
822838

823839
auto bottom = jmax (0.0f, (float) bottomY - getTextStorageHeight());
824840

modules/juce_gui_basics/widgets/juce_TextEditorModel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ class TextEditor::ParagraphsModel
202202

203203
bool isEmpty() const { return storage.empty(); }
204204

205+
ParagraphItem front() const
206+
{
207+
jassert (! ranges.isEmpty());
208+
return { ranges.get (0), storage.front() };
209+
}
210+
205211
ParagraphItem back() const
206212
{
207213
jassert (! ranges.isEmpty());
@@ -417,6 +423,7 @@ class TextEditor::TextEditorStorage
417423
auto end() const { return paragraphs.end(); }
418424

419425
auto isEmpty() const { return paragraphs.isEmpty(); }
426+
auto front() const { return paragraphs.front(); }
420427
auto back() const { return paragraphs.back(); }
421428

422429
std::optional<Font> getLastFont() const

0 commit comments

Comments
 (0)