Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. Index: lib/redmine/unified_diff.rb
  2. ===================================================================
  3. --- lib/redmine/unified_diff.rb (revision 4232)
  4. +++ lib/redmine/unified_diff.rb (working copy)
  5. @@ -38,9 +38,78 @@
  6. end
  7. end
  8. self << diff_table unless diff_table.empty?
  9. +
  10. + each do |table|
  11. + lines = { 'left' => [], 'right' => [] }
  12. + table.keys.sort.each do |key|
  13. + v = table[key]
  14. + if v.same?
  15. + count = min(lines['left'].length, lines['right'].length)
  16. + 0.upto(count - 1) do |idx|
  17. + l = lines['left'][idx]
  18. + r = lines['right'][idx]
  19. +
  20. + table[l].line_left, table[r].line_right = highlight(table[l].line_left, table[r].line_right)
  21. + end
  22. +
  23. + lines = { 'left' => [], 'right' => [] }
  24. + next
  25. + end
  26. +
  27. + unless v.type_diff_left.empty?
  28. + lines['left'] << key
  29. + end
  30. + unless v.type_diff_right.empty?
  31. + lines['right'] << key
  32. + end
  33. + end
  34. +
  35. + count = min(lines['left'].length, lines['right'].length)
  36. + 0.upto(count - 1) do |idx|
  37. + l = lines['left'][idx]
  38. + r = lines['right'][idx]
  39. +
  40. + table[l].line_left, table[r].line_right = highlight(table[l].line_left, table[r].line_right)
  41. + end
  42. + end
  43. +
  44. self
  45. end
  46.  
  47. + def max(a, b)
  48. + [a, b].max
  49. + end
  50. +
  51. + def min(a, b)
  52. + [a, b].min
  53. + end
  54. +
  55. + def highlight(src, dst)
  56. + def get_change_extent(src, dst)
  57. + start = 0
  58. + limit = min(src.length, dst.length)
  59. + while start < limit and src[start] == dst[start]
  60. + start += 1
  61. + end
  62. + stop = -1
  63. + limit = limit - start
  64. + while -stop <= limit and src[stop] == dst[stop]
  65. + stop -= 1
  66. + end
  67. + [start, stop + 1]
  68. + end
  69. +
  70. + start, stop = get_change_extent(src, dst)
  71. + if start != 0 or stop != 0
  72. + last = stop + src.length
  73. + src = src[0, start] + '<del>' + src[start, last - start] + '</del>' + src[last, src.length]
  74. +
  75. + last = stop + dst.length
  76. + dst = dst[0, start] + '<ins>' + dst[start, last - start] + '</ins>' + dst[last, dst.length]
  77. + end
  78. + [src, dst]
  79. + end
  80. +
  81. def truncated?; @truncated; end
  82. end
  83.  
  84. @@ -186,5 +255,9 @@
  85. puts self.nb_line_right
  86. puts self.line_right
  87. end
  88. +
  89. + def same?
  90. + @type_diff_left.empty? and @type_diff_right.empty?
  91. + end
  92. end
  93. end
  94. Index: public/stylesheets/scm.css
  95. ===================================================================
  96. --- public/stylesheets/scm.css (revision 4232)
  97. +++ public/stylesheets/scm.css (working copy)
  98. @@ -193,3 +193,13 @@
  99. .syntaxhl .del .del { color: #800; font-weight:bold }
  100. .syntaxhl .chg .chg { color: #66f; }
  101. .syntaxhl .head .head { color: #f4f; }
  102. +
  103. +.syntaxhl td ins, .syntaxhl td del { text-decoration: none; }
  104. +.syntaxhl ins {
  105. + background: #9e9;
  106. + color: #000;
  107. +}
  108. +.syntaxhl del {
  109. + background: #e99;
  110. + color: #000;
  111. +}
  112. \ No newline at end of file
Add Comment
Please, Sign In to add comment