Commit e6b2f2fc authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Simplify handling of out-of-bound end offset in PlainTextRange::CreateRangeFor()

This patch refactors the function, so that it uses distinct return paths
for in-bound and out-of-bound end offsets, so that the code flow logic
is cleaner.

Bug: 828719
Change-Id: I5c4553b4e5480a2fcf0b2496e0153f648c002bb3
Reviewed-on: https://chromium-review.googlesource.com/999160
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549283}
parent 426a021c
......@@ -160,22 +160,22 @@ EphemeralRange PlainTextRange::CreateRangeFor(
result_end = CreatePositionInTextRun(End() - doc_text_position,
text_run_start_position,
text_run_end_position);
doc_text_position += len;
break;
DCHECK(start_range_found);
return EphemeralRange(result_start.ToOffsetInAnchor(),
result_end.ToOffsetInAnchor());
}
doc_text_position += len;
}
// Start() is out of bounds
if (!start_range_found)
return EphemeralRange();
if (length() && End() > doc_text_position) { // End() is out of bounds
result_end = text_run_end_position;
}
// End() is out of bounds
return EphemeralRange(result_start.ToOffsetInAnchor(),
result_end.ToOffsetInAnchor());
text_run_end_position.ToOffsetInAnchor());
}
PlainTextRange PlainTextRange::Create(const ContainerNode& scope,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment