Commit 362b0c75 authored by joone.hur's avatar joone.hur Committed by Commit bot

Restore a collapsed leading space of text used for line break

When a text is wrapped during layout, the leading space of the
text can be collapsed and a line break is inserted instead of
the space. In this case, we need to restore the collapsed space
when we copy the text.

This CL can handle the following case:
<div style="width: 2em;"><b><i>foo</i></b> bar</div>

BUG=318925
TEST=editing/pasteboard/restore-collapsed-space-for-copy.html

Review-Url: https://codereview.chromium.org/2320533002
Cr-Commit-Position: refs/heads/master@{#417155}
parent b918a399
......@@ -10,7 +10,7 @@ test(() => assert_selection(
selection.document.execCommand('paste');
},
'<div style="width: 10em;">Copy this area <a href="http://foo/">AVeryLongWordThatWillWrap</a></div><div contenteditable>Copy this area <a href="http://foo/">AVeryLongWordThatWillWrap|</a></div>'),
'1. Restore the collapsed space');
'1. Restore the collapsed trailing space');
test(() => assert_selection(
'<div style="width: 2em;"><b><i>foo </i></b>bar</div><div contenteditable>|</div>',
......@@ -19,7 +19,16 @@ test(() => assert_selection(
selection.document.execCommand('paste');
},
'<div style="width: 2em;"><b><i>foo </i></b>bar</div><div contenteditable><b><i>foo </i></b>bar|</div>'),
'2. Restore the collapsed space');
'2. Restore the collapsed trailing space');
test(() => assert_selection(
'<div style="width: 2em;"><b><i>foo</i></b> bar</div><div contenteditable>|</div>',
selection => {
selection.setClipboardData('<b><i>foo</i></b> bar');
selection.document.execCommand('paste');
},
'<div style="width: 2em;"><b><i>foo</i></b> bar</div><div contenteditable><b><i>foo</i></b> bar|</div>'),
'3. Restore the collapsed leading space');
test(() => assert_selection(
'<div style="width: 2em;">작은홍띠점박이푸른부전나비</div><div contenteditable>|</div>',
......@@ -28,7 +37,7 @@ test(() => assert_selection(
selection.document.execCommand('paste');
},
'<div style="width: 2em;">작은홍띠점박이푸른부전나비</div><div contenteditable>작은홍띠점박이푸른부전나비|</div>'),
'3. Space should not be added for CJK');
'4. Space should not be added for CJK');
test(() => assert_selection(
'<div style="width: 2em; word-break: break-all">Pneumonoultramicroscopicsilicovolcanoconiosis</div><div contenteditable>|</div>',
......@@ -37,5 +46,5 @@ test(() => assert_selection(
selection.document.execCommand('paste');
},
'<div style="width: 2em; word-break: break-all">Pneumonoultramicroscopicsilicovolcanoconiosis</div><div contenteditable>Pneumonoultramicroscopicsilicovolcanoconiosis|</div>'),
'4. Space should not be added for CSS word-break: break-all');
'5. Space should not be added for CSS word-break: break-all');
</script>
......@@ -611,12 +611,22 @@ void TextIteratorAlgorithm<Strategy>::handleTextBox()
size_t subrunEnd = str.find('\n', runStart);
if (subrunEnd == kNotFound || subrunEnd > runEnd) {
subrunEnd = runEnd;
// Restore the collapsed trailing space for copy & paste.
// Restore the collapsed space for copy & paste.
// See http://crbug.com/318925
// For trailing space.
if (!nextTextBox && m_textBox->root().nextRootBox() && m_textBox->root().lastChild() == m_textBox) {
if (str.endsWith(' ') && subrunEnd == str.length() - 1 && str[subrunEnd - 1] != ' ')
++subrunEnd;
}
// For leading space.
if (m_textBox->root().prevRootBox() && m_textBox->root().firstChild() == m_textBox) {
InlineBox* lastChildOfPrevRoot = m_textBox->root().prevRootBox()->lastChild();
if (!lastChildOfPrevRoot->isText() && !lastChildOfPrevRoot->getLineLayoutItem().isBR()
&& !lastChildOfPrevRoot->isInlineFlowBox()) {
if (runStart > 0 && str[0] == ' ')
--runStart;
}
}
}
m_offset = subrunEnd;
......
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