[meld] Fix spurious newline when CRLF splits over boundary (closes bgo#623076)



commit 17124883d91f220498ce9404e62f5bad7f7737a3
Author: Piotr Piastucki <leech miranda gmail com>
Date:   Mon May 31 08:42:00 2010 +0200

    Fix spurious newline when CRLF splits over boundary (closes bgo#623076)
    
    When CRLF appears exactly at the 4kb boundary a superfluous empty line
    is inserted because CR and LF are separately inserted into text buffer.
    This patch fixes the issue by adding a simple check for CR occurence at
    the end of string being inserted.

 meld/filediff.py |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index a59da8b..828c278 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -731,7 +731,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                                        buf = buf,
                                        codec = try_codecs[:],
                                        text = [],
-                                       pane = i)
+                                       pane = i,
+                                       was_cr = False)
                     tasks.append(task)
                 except (IOError, LookupError), e:
                     buf.delete(*buf.get_bounds())
@@ -769,7 +770,16 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                                     _("Could not read file"), str(ioerr))
                     tasks.remove(t)
                 else:
+                    # The handling here avoids inserting split CR/LF pairs into
+                    # GtkTextBuffers; this is relevant only when universal
+                    # newline support is unavailable or broken.
+                    if t.was_cr:
+                        nextbit = "\r" + nextbit
+                        t.was_cr = False
                     if len(nextbit):
+                        if (nextbit[-1] == "\r"):
+                            t.was_cr = True
+                            nextbit = nextbit[0:-1]
                         t.buf.insert( t.buf.get_end_iter(), nextbit )
                         t.text.append(nextbit)
                     else:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]