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

Make EndOfSentence stop at block boundaries

This patch stops EndOfSentence from crossing block boundaries, since
block boundaries are also sentence boundaries.

Bug: 778507
Change-Id: I19ec97de1bbaac50db4c55b38ffb158339003993
Reviewed-on: https://chromium-review.googlesource.com/c/1337432Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608850}
parent 390c941f
......@@ -85,6 +85,14 @@ function runTests() {
assert_equals(actual, 'multiple lines.');
}, 'sentence11');
// Sentence end expansion should not cross block boundaries.
test(() => {
const id = 'begin';
const length = document.getElementById(id).firstChild.length;
const actual = expandRangeString(id, length, id, length, 'sentence', true);
assert_equals(actual, 'Each sentence begins with capital\nletter and ends with a punctuation.');
}, 'sentence12');
// Expand word.
// Same range start and end, both at the begin of word.
test(() => {
......@@ -218,7 +226,7 @@ function runTests() {
}
</script>
<body>
<p>This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital
<p id="begin">This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital
letter and ends with a punctuation.
</p>
<pre id="multilineSentence">Now, a sentence
......
......@@ -103,8 +103,13 @@ PositionInFlatTree EndOfSentenceInternal(const PositionInFlatTree& position) {
// between sentences.
const unsigned offset = FindNonSpaceCharacter(text, passed_offset);
const int result = iterator->following(offset);
if (result == kTextBreakDone)
if (result == kTextBreakDone) {
if (text.length()) {
// Block boundaries are also sentence boundaries.
return Position::After(text.length());
}
return Position();
}
return result == 0 ? Position::Before(0) : Position::After(result - 1);
}
......
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