Select a position on an empty line

Bugs: skia:10821
Change-Id: I26746e7baa143a6be7afdc91c994e4b8731d07f7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324879
Commit-Queue: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Julia Lavrova 2020-10-09 15:14:22 -04:00 committed by Skia Commit-Bot
parent 7bbdde0596
commit 87cb9a4a10
2 changed files with 16 additions and 2 deletions

View File

@ -1085,6 +1085,13 @@ void TextLine::getRectsForRange(TextRange textRange0,
PositionWithAffinity TextLine::getGlyphPositionAtCoordinate(SkScalar dx) {
if (SkScalarNearlyZero(this->width())) {
// TODO: this is one of the flutter changes that have to go away eventually
// Empty line is a special case in txtlib
auto utf16Index = fOwner->getUTF16Index(this->fClusterRange.start);
return { SkToS32(utf16Index) , kDownstream };
}
PositionWithAffinity result(0, Affinity::kDownstream);
this->iterateThroughVisualRuns(true,
[this, dx, &result]

View File

@ -4826,6 +4826,8 @@ DEF_TEST(SkParagraph_EmptyParagraphWithLineBreak, reporter) {
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>();
if (!fontCollection->fontsFound()) return;
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
fontCollection->enableFontFallback();
TestCanvas canvas("SkParagraph_EmptyParagraphWithLineBreak.png");
ParagraphStyle paragraph_style;
@ -4833,12 +4835,17 @@ DEF_TEST(SkParagraph_EmptyParagraphWithLineBreak, reporter) {
text_style.setFontSize(16);
text_style.setFontFamilies({SkString("Roboto")});
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
builder.addText("\n", 1);
builder.addText("abc\n\ndef");
auto paragraph = builder.Build();
paragraph->layout(TestCanvasWidth);
paragraph->paint(canvas.get(), 0, 0);
auto result = paragraph->getRectsForPlaceholders();
// Select a position at the second (empty) line
auto pos = paragraph->getGlyphPositionAtCoordinate(0, 21);
REPORTER_ASSERT(reporter, pos.affinity == Affinity::kDownstream && pos.position == 4);
auto rect = paragraph->getRectsForRange(4, 5, RectHeightStyle::kTight, RectWidthStyle::kTight);
REPORTER_ASSERT(reporter, rect.size() == 1 && rect[0].rect.width() == 0);
}
DEF_TEST(SkParagraph_NullInMiddleOfText, reporter) {