[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Need help with newline handling
From:       Harri Porten <porten () froglogic ! com>
Date:       2010-02-28 14:10:10
Message-ID: Pine.LNX.4.64.1002281453510.27193 () greco ! froglogic ! com
[Download RAW message or body]

Hello,

I need some advise on how to handle 
https://bugs.kde.org/show_bug.cgi?id=58111 which is about copy&paste 
problems. What happens is that a user who copies HTML like this

==============
<p>coucou<br>
hop<br>
==============

gets the text "coucou<newline><space>hop". The leading space is 
superfluous. I've tracked it down to the following: setText() is called on 
the RenderText object for the "hop" string. It has a leading newline 
character which gets turned into a space by 
DOMString::collapseWhiteSpace()[1]. Since our copy&paste code makes us of 
the text stored in the Render objects it'll put this space into the 
clipboard as well.

I wonder if it's the right thing to convert leading newlines that way. 
Trying a patch that collapses leading newlines completely (attached) but 
got a lot of visible regressions from our test suite.

My question: is the collapsing code in RenderText::setText() the right 
place to fix the issue? Or should I restrict the fix to the 
KHTMLPart::selectedText() function?

Harri.

[1] http://www.w3.org/TR/css3-text/#white-space-processing

["collapse.diff" (TEXT/x-diff)]

Index: xml/dom_stringimpl.cpp
===================================================================
--- xml/dom_stringimpl.cpp	(revision 1096575)
+++ xml/dom_stringimpl.cpp	(working copy)
@@ -224,6 +224,9 @@
         if (ch == '\t') ch = ' ';
 
         if (!preserveLF && ch == '\n') {
+            // strip leading newlines
+            if (pos == 0)
+                continue;
             // ### Not strictly correct according to CSS3 text-module.
             // - In ideographic languages linefeed should be ignored
             // - and in Thai and Khmer it should be treated as a zero-width space


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic