Skip to content

Commit 8ead50d

Browse files
committed
Prepare for 2.0.0-beta17 release
1 parent fc423e6 commit 8ead50d

File tree

8 files changed

+94
-7
lines changed

8 files changed

+94
-7
lines changed

CREDITS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ Mikko Rantanen, [@Rantanen](https://github.com/Rantanen)
2121
Wolfgang Illmeyer, [@escitalopram](https://github.com/escitalopram)
2222

2323
Jameskmonger, [@Jameskmonger](https://github.com/Jameskmonger)
24+
25+
Rafael Cortês, [@mrfyda](https://github.com/mrfyda)
26+
27+
Ivan Vorontsov, [@lantian](https://github.com/lantian)

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ diff2html generates pretty HTML diffs from git diff output.
1919

2020
## Features
2121

22-
* `line-by-line` and `side-by-side` diff
22+
* Line by line and Side by side diff
2323

24-
* new and old line numbers
24+
* New and old line numbers
2525

26-
* inserted and removed lines
26+
* Inserted and removed lines
2727

2828
* GitHub like style
2929

3030
* Code syntax highlight
3131

3232
* Line similarity matching
3333

34+
* Easy code selection
35+
3436
## Online Example
3537

3638
> Go to [diff2html](http://rtfpessoa.github.io/diff2html/)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta16",
3+
"version": "2.0.0-beta17",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html-ui.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
var diffJson = null;
1818
var defaultTarget = "body";
19+
var currentSelectionColumnId = -1;
1920

2021
function Diff2HtmlUI(config) {
2122
var cfg = config || {};
@@ -25,6 +26,8 @@
2526
} else if (cfg.json) {
2627
diffJson = cfg.json;
2728
}
29+
30+
this._initSelection();
2831
}
2932

3033
Diff2HtmlUI.prototype.draw = function(targetId, config) {
@@ -132,6 +135,54 @@
132135
});
133136
};
134137

138+
Diff2HtmlUI.prototype._initSelection = function() {
139+
var body = $('body');
140+
var that = this;
141+
142+
body.on('mousedown', '.d2h-diff-table', function(event) {
143+
var target = $(event.target);
144+
var table = target.closest('.d2h-diff-table');
145+
146+
if (target.closest('.d2h-code-line,.d2h-code-side-line').length) {
147+
table.removeClass('selecting-left');
148+
table.addClass('selecting-right');
149+
currentSelectionColumnId = 1;
150+
} else if (target.closest('.d2h-code-linenumber,.d2h-code-side-linenumber').length) {
151+
table.removeClass('selecting-right');
152+
table.addClass('selecting-left');
153+
currentSelectionColumnId = 0;
154+
}
155+
});
156+
157+
body.on('copy', '.d2h-diff-table', function(event) {
158+
var clipboardData = event.originalEvent.clipboardData;
159+
var text = that._getSelectedText();
160+
clipboardData.setData('text', text);
161+
event.preventDefault();
162+
});
163+
};
164+
165+
166+
Diff2HtmlUI.prototype._getSelectedText = function() {
167+
var sel = window.getSelection();
168+
var range = sel.getRangeAt(0);
169+
var doc = range.cloneContents();
170+
var nodes = doc.querySelectorAll('tr');
171+
var text = '';
172+
var idx = currentSelectionColumnId;
173+
174+
if (nodes.length === 0) {
175+
text = doc.textContent;
176+
} else {
177+
[].forEach.call(nodes, function(tr, i) {
178+
var td = tr.cells[tr.cells.length === 1 ? 0 : idx];
179+
text += (i ? '\n' : '') + td.textContent.replace(/(?:\r\n|\r|\n)/g, '');
180+
});
181+
}
182+
183+
return text;
184+
};
185+
135186
module.exports.Diff2HtmlUI = Diff2HtmlUI;
136187

137188
// Expose diff2html in the browser

dist/diff2html-ui.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/diff2html.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,33 @@ ins.d2h-change, del.d2h-change {
274274
font-size: 10px;
275275
cursor: pointer;
276276
}
277+
278+
/*
279+
* Selection util.
280+
*/
281+
282+
.selecting-left .d2h-code-line,
283+
.selecting-left .d2h-code-line *,
284+
.selecting-right td.d2h-code-linenumber,
285+
.selecting-right td.d2h-code-linenumber *,
286+
.selecting-left .d2h-code-side-line,
287+
.selecting-left .d2h-code-side-line *,
288+
.selecting-right td.d2h-code-side-linenumber,
289+
.selecting-right td.d2h-code-side-linenumber *{
290+
-webkit-touch-callout: none;
291+
-webkit-user-select: none;
292+
-khtml-user-select: none;
293+
-moz-user-select: none;
294+
-ms-user-select: none;
295+
user-select: none;
296+
}
297+
298+
.selecting-left .d2h-code-line::selection,
299+
.selecting-left .d2h-code-line *::selection
300+
.selecting-right td.d2h-code-linenumber::selection,
301+
.selecting-left .d2h-code-side-line::selection,
302+
.selecting-left .d2h-code-side-line *::selection,
303+
.selecting-right td.d2h-code-side-linenumber::selection,
304+
.selecting-right td.d2h-code-side-linenumber *::selection {
305+
background: transparent;
306+
}

dist/diff2html.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta16",
3+
"version": "2.0.0-beta17",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

0 commit comments

Comments
 (0)