Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: lib/redmine/unified_diff.rb
- ===================================================================
- --- lib/redmine/unified_diff.rb (revision 4232)
- +++ lib/redmine/unified_diff.rb (working copy)
- @@ -38,9 +38,78 @@
- end
- end
- self << diff_table unless diff_table.empty?
- +
- + each do |table|
- + lines = { 'left' => [], 'right' => [] }
- + table.keys.sort.each do |key|
- + v = table[key]
- + if v.same?
- + count = min(lines['left'].length, lines['right'].length)
- + 0.upto(count - 1) do |idx|
- + l = lines['left'][idx]
- + r = lines['right'][idx]
- +
- + table[l].line_left, table[r].line_right = highlight(table[l].line_left, table[r].line_right)
- + end
- +
- + lines = { 'left' => [], 'right' => [] }
- + next
- + end
- +
- + unless v.type_diff_left.empty?
- + lines['left'] << key
- + end
- + unless v.type_diff_right.empty?
- + lines['right'] << key
- + end
- + end
- +
- + count = min(lines['left'].length, lines['right'].length)
- + 0.upto(count - 1) do |idx|
- + l = lines['left'][idx]
- + r = lines['right'][idx]
- +
- + table[l].line_left, table[r].line_right = highlight(table[l].line_left, table[r].line_right)
- + end
- + end
- +
- self
- end
- + def max(a, b)
- + [a, b].max
- + end
- +
- + def min(a, b)
- + [a, b].min
- + end
- +
- + def highlight(src, dst)
- + def get_change_extent(src, dst)
- + start = 0
- + limit = min(src.length, dst.length)
- + while start < limit and src[start] == dst[start]
- + start += 1
- + end
- + stop = -1
- + limit = limit - start
- + while -stop <= limit and src[stop] == dst[stop]
- + stop -= 1
- + end
- + [start, stop + 1]
- + end
- +
- + start, stop = get_change_extent(src, dst)
- + if start != 0 or stop != 0
- + last = stop + src.length
- + src = src[0, start] + '<del>' + src[start, last - start] + '</del>' + src[last, src.length]
- +
- + last = stop + dst.length
- + dst = dst[0, start] + '<ins>' + dst[start, last - start] + '</ins>' + dst[last, dst.length]
- + end
- + [src, dst]
- + end
- +
- def truncated?; @truncated; end
- end
- @@ -186,5 +255,9 @@
- puts self.nb_line_right
- puts self.line_right
- end
- +
- + def same?
- + @type_diff_left.empty? and @type_diff_right.empty?
- + end
- end
- end
- Index: public/stylesheets/scm.css
- ===================================================================
- --- public/stylesheets/scm.css (revision 4232)
- +++ public/stylesheets/scm.css (working copy)
- @@ -193,3 +193,13 @@
- .syntaxhl .del .del { color: #800; font-weight:bold }
- .syntaxhl .chg .chg { color: #66f; }
- .syntaxhl .head .head { color: #f4f; }
- +
- +.syntaxhl td ins, .syntaxhl td del { text-decoration: none; }
- +.syntaxhl ins {
- + background: #9e9;
- + color: #000;
- +}
- +.syntaxhl del {
- + background: #e99;
- + color: #000;
- +}
- \ No newline at end of file
Add Comment
Please, Sign In to add comment