[gitg/wip/patch-stage] Calculate offsets correctly



commit d35cc867e5fa5511b90a64c78605f6b522f0fe46
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Thu Jan 2 13:29:10 2014 +0100

    Calculate offsets correctly

 libgitg/resources/diff-view.js |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index 191a2a6..cb0a9db 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -185,7 +185,6 @@ function prepare_patchset(filediv)
        elem = next_element(elem);
 
        var patches = [];
-
        var doffset = 0;
 
        var a = "a".charCodeAt(0);
@@ -220,13 +219,24 @@ function prepare_patchset(filediv)
                        }
                        else
                        {
+                               var o = {old: offset, new: offset};
+
+                               if (added)
+                               {
+                                       o.old -= doffset;
+                               }
+                               else
+                               {
+                                       o.new += doffset;
+                               }
+
                                // [sign, old_offset, new_offset, length]
-                               last = [tp, offset + doffset, offset, length];
+                               last = [tp, o.old, o.new, length];
                                patches.push(last);
                        }
                }
 
-               doffset += added ? -length : length;
+               doffset += added ? length : -length;
        }
 
        var filename = filediv.getAttribute('data-filename');


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