Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Issue 753573003: Copy and paste sometimes removes spaces between words. (Closed)

Created:
6 years ago by c.shu
Modified:
3 years, 3 months ago
CC:
blink-reviews
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Project:
blink
Visibility:
Public.

Description

Copy and paste sometimes removes spaces between words. The problem is StyledMarkupAccumulator uses renderedText and the space at the end of the text has been stripped when the tag after the text was wrapped. BUG=318925 In the DOM tree, the copied content is represented by two nodes, one is "Copy this text " and the 2nd one is the anchor. When the code tries to convert the 1st node to plain text, it uses a text iterator to scan through the text. However, the spaces at the ending of the 1st node were lost because they were collapsed during rendering. This patch restores the missing space if it detects there is a non-text node following the last text node. This information has to be passed into the textIterator when it was constructed in StyledMarkupAccumulator::renderedText.

Patch Set 1 #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+85 lines, -6 lines) Patch
A LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag.html View 1 chunk +42 lines, -0 lines 0 comments Download
A LayoutTests/editing/pasteboard/copy-text-with-wrapped-tag-expected.txt View 1 chunk +20 lines, -0 lines 0 comments Download
M Source/core/editing/TextIterator.h View 2 chunks +4 lines, -1 line 0 comments Download
M Source/core/editing/TextIterator.cpp View 2 chunks +8 lines, -0 lines 4 comments Download
M Source/core/editing/markup.cpp View 1 chunk +11 lines, -5 lines 0 comments Download

Messages

Total messages: 11 (6 generated)
c.shu
I come up with a new patch that fixes the bug 318925. Comparing to my ...
6 years ago (2014-12-09 00:07:16 UTC) #2
c.shu
ping reviewers.
6 years ago (2014-12-11 20:48:46 UTC) #4
tkent
+yosin
6 years ago (2014-12-12 00:23:03 UTC) #9
yosin_UTC9
https://codereview.chromium.org/753573003/diff/1/Source/core/editing/TextIterator.cpp File Source/core/editing/TextIterator.cpp (right): https://codereview.chromium.org/753573003/diff/1/Source/core/editing/TextIterator.cpp#newcode271 Source/core/editing/TextIterator.cpp:271: , m_hasNodesFollowing(behavior & TextIteratorBehavesAsIfNodesFollowing) Do we need to have ...
5 years, 11 months ago (2015-01-14 01:46:20 UTC) #10
c.shu
5 years, 11 months ago (2015-01-14 21:13:41 UTC) #11
https://codereview.chromium.org/753573003/diff/1/Source/core/editing/TextIter...
File Source/core/editing/TextIterator.cpp (right):

https://codereview.chromium.org/753573003/diff/1/Source/core/editing/TextIter...
Source/core/editing/TextIterator.cpp:271: , m_hasNodesFollowing(behavior &
TextIteratorBehavesAsIfNodesFollowing)
On 2015/01/14 01:46:20, Yosi_UTC9 wrote:
> Do we need to have new behavior? It seems the issue is caused by word wrapping
> and all call sites want to have a space at wrapped position.

The bug is not a general issue. It only shows up when the text node is followed
by a non-text node. See function renderedText(...) in mark.cpp. The new behavior
is set when the textNode is not range->endContainer(). This info is lost when
constructing a new Range using textNode with startOffset and endOffset. So we
have to pass it through the constructor.

https://codereview.chromium.org/753573003/diff/1/Source/core/editing/TextIter...
Source/core/editing/TextIterator.cpp:749: if
(m_lastTextNodeEndedWithCollapsedSpace && !nextTextBox && m_hasNodesFollowing) {
On 2015/01/14 01:46:20, Yosi_UTC9 wrote:
> Sorry, I'm not sure why newline character is a special case.

We don't want to restore the space for newline as it's taken care of already in
the exiting code. Otherwise, we see extra space in the paste.

Powered by Google App Engine
This is Rietveld 408576698