From 8ead50d8b258f475ee7b712818c48195315f19dc Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sun, 1 May 2016 20:52:25 +0100 Subject: [PATCH] Prepare for 2.0.0-beta17 release --- CREDITS.md | 4 ++++ README.md | 8 ++++--- bower.json | 2 +- dist/diff2html-ui.js | 51 ++++++++++++++++++++++++++++++++++++++++ dist/diff2html-ui.min.js | 2 +- dist/diff2html.css | 30 +++++++++++++++++++++++ dist/diff2html.min.css | 2 +- package.json | 2 +- 8 files changed, 94 insertions(+), 7 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index 51a1ac3..8a5f5da 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -21,3 +21,7 @@ Mikko Rantanen, [@Rantanen](https://github.com/Rantanen) Wolfgang Illmeyer, [@escitalopram](https://github.com/escitalopram) Jameskmonger, [@Jameskmonger](https://github.com/Jameskmonger) + +Rafael Cortês, [@mrfyda](https://github.com/mrfyda) + +Ivan Vorontsov, [@lantian](https://github.com/lantian) diff --git a/README.md b/README.md index 493b2f9..57a8224 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ diff2html generates pretty HTML diffs from git diff output. ## Features -* `line-by-line` and `side-by-side` diff +* Line by line and Side by side diff -* new and old line numbers +* New and old line numbers -* inserted and removed lines +* Inserted and removed lines * GitHub like style @@ -31,6 +31,8 @@ diff2html generates pretty HTML diffs from git diff output. * Line similarity matching +* Easy code selection + ## Online Example > Go to [diff2html](http://rtfpessoa.github.io/diff2html/) diff --git a/bower.json b/bower.json index 87b6097..7086a8f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "diff2html", - "version": "2.0.0-beta16", + "version": "2.0.0-beta17", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [ diff --git a/dist/diff2html-ui.js b/dist/diff2html-ui.js index 550e6b0..c111a95 100644 --- a/dist/diff2html-ui.js +++ b/dist/diff2html-ui.js @@ -16,6 +16,7 @@ var diffJson = null; var defaultTarget = "body"; + var currentSelectionColumnId = -1; function Diff2HtmlUI(config) { var cfg = config || {}; @@ -25,6 +26,8 @@ } else if (cfg.json) { diffJson = cfg.json; } + + this._initSelection(); } Diff2HtmlUI.prototype.draw = function(targetId, config) { @@ -132,6 +135,54 @@ }); }; + Diff2HtmlUI.prototype._initSelection = function() { + var body = $('body'); + var that = this; + + body.on('mousedown', '.d2h-diff-table', function(event) { + var target = $(event.target); + var table = target.closest('.d2h-diff-table'); + + if (target.closest('.d2h-code-line,.d2h-code-side-line').length) { + table.removeClass('selecting-left'); + table.addClass('selecting-right'); + currentSelectionColumnId = 1; + } else if (target.closest('.d2h-code-linenumber,.d2h-code-side-linenumber').length) { + table.removeClass('selecting-right'); + table.addClass('selecting-left'); + currentSelectionColumnId = 0; + } + }); + + body.on('copy', '.d2h-diff-table', function(event) { + var clipboardData = event.originalEvent.clipboardData; + var text = that._getSelectedText(); + clipboardData.setData('text', text); + event.preventDefault(); + }); + }; + + + Diff2HtmlUI.prototype._getSelectedText = function() { + var sel = window.getSelection(); + var range = sel.getRangeAt(0); + var doc = range.cloneContents(); + var nodes = doc.querySelectorAll('tr'); + var text = ''; + var idx = currentSelectionColumnId; + + if (nodes.length === 0) { + text = doc.textContent; + } else { + [].forEach.call(nodes, function(tr, i) { + var td = tr.cells[tr.cells.length === 1 ? 0 : idx]; + text += (i ? '\n' : '') + td.textContent.replace(/(?:\r\n|\r|\n)/g, ''); + }); + } + + return text; + }; + module.exports.Diff2HtmlUI = Diff2HtmlUI; // Expose diff2html in the browser diff --git a/dist/diff2html-ui.min.js b/dist/diff2html-ui.min.js index e7685fa..8362987 100644 --- a/dist/diff2html-ui.min.js +++ b/dist/diff2html-ui.min.js @@ -1 +1 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o*{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px}.d2h-lines-deleted{text-align:left}.d2h-lines-deleted>*{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px}.d2h-file-name-wrapper{display:inline-flex;width:90%}.d2h-file-name{line-height:33px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-file-diff,.d2h-file-side-diff{overflow-x:scroll;overflow-y:hidden}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;width:100%}.d2h-diff-tbody>tr>td>div{height:16px;line-height:16px}.d2h-files-diff{width:100%}.d2h-file-side-diff{display:inline-block;width:50%;margin-right:-4px}.d2h-code-line{display:block;white-space:nowrap;padding:0 10px;margin-left:80px}.d2h-code-side-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:50px;color:inherit;overflow-x:inherit;background:0 0}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#ffb6ba;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#97f295;border-radius:.2em}.d2h-code-line-ctn,.d2h-code-line-prefix{background:0 0;padding:0}.d2h-code-linenumber,.d2h-code-side-linenumber{position:absolute;height:18px;line-height:18px;background-color:#fff;text-align:right;color:rgba(0,0,0,.3);cursor:pointer}.line-num1,.line-num2{width:40px;padding-left:3px;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis}.line-num2{float:right}.d2h-code-linenumber{box-sizing:border-box;width:86px;padding-left:2px;padding-right:2px;border:solid #eee;border-width:0 1px}.d2h-code-side-linenumber{box-sizing:border-box;width:56px;padding-left:5px;padding-right:5px;border:solid #eee;border-width:0 1px;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#fee8e9;border-color:#e9aeae}.d2h-ins{background-color:#dfd;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,.3);border-color:#d5e4f2}.d2h-del.d2h-change,.d2h-ins.d2h-change{background-color:#ffc}del.d2h-change,ins.d2h-change{background-color:#fad771}.d2h-file-diff .d2h-del.d2h-change{background-color:#fae1af}.d2h-file-diff .d2h-ins.d2h-change{background-color:#ded}.d2h-file-list-wrapper{margin-bottom:10px}.d2h-file-list-wrapper a{text-decoration:none;color:#3572b0}.d2h-file-list-wrapper a:visited{color:#3572b0}.d2h-file-list-header{text-align:left}.d2h-file-list-title{font-weight:700}.d2h-file-list-line{text-align:left;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-list-line .d2h-file-name{line-height:21px}.d2h-file-list{display:block}.d2h-file-switch{display:none;font-size:10px;cursor:pointer} \ No newline at end of file +.d2h-code-line-prefix,.line-num1{float:left}.d2h-wrapper{text-align:left}.d2h-file-header{padding:5px 10px;border-bottom:1px solid #d8d8d8;background-color:#f7f7f7;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-stats{display:inline;font-size:12px;text-align:center}.d2h-lines-added{text-align:right}.d2h-lines-added>*{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px}.d2h-lines-deleted{text-align:left}.d2h-lines-deleted>*{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px}.d2h-file-name-wrapper{display:inline-flex;width:90%}.d2h-file-name{line-height:33px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-file-diff,.d2h-file-side-diff{overflow-x:scroll;overflow-y:hidden}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;width:100%}.d2h-diff-tbody>tr>td>div{height:16px;line-height:16px}.d2h-files-diff{width:100%}.d2h-file-side-diff{display:inline-block;width:50%;margin-right:-4px}.d2h-code-line{display:block;white-space:nowrap;padding:0 10px;margin-left:80px}.d2h-code-side-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:50px;color:inherit;overflow-x:inherit;background:0 0}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#ffb6ba;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#97f295;border-radius:.2em}.d2h-code-line-ctn,.d2h-code-line-prefix{background:0 0;padding:0}.d2h-code-linenumber,.d2h-code-side-linenumber{position:absolute;height:18px;line-height:18px;background-color:#fff;text-align:right;color:rgba(0,0,0,.3);cursor:pointer}.line-num1,.line-num2{width:40px;padding-left:3px;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis}.line-num2{float:right}.d2h-code-linenumber{box-sizing:border-box;width:86px;padding-left:2px;padding-right:2px;border:solid #eee;border-width:0 1px}.d2h-code-side-linenumber{box-sizing:border-box;width:56px;padding-left:5px;padding-right:5px;border:solid #eee;border-width:0 1px;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#fee8e9;border-color:#e9aeae}.d2h-ins{background-color:#dfd;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,.3);border-color:#d5e4f2}.d2h-del.d2h-change,.d2h-ins.d2h-change{background-color:#ffc}del.d2h-change,ins.d2h-change{background-color:#fad771}.d2h-file-diff .d2h-del.d2h-change{background-color:#fae1af}.d2h-file-diff .d2h-ins.d2h-change{background-color:#ded}.d2h-file-list-wrapper{margin-bottom:10px}.d2h-file-list-wrapper a{text-decoration:none;color:#3572b0}.d2h-file-list-wrapper a:visited{color:#3572b0}.d2h-file-list-header{text-align:left}.d2h-file-list-title{font-weight:700}.d2h-file-list-line{text-align:left;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-list-line .d2h-file-name{line-height:21px}.d2h-file-list{display:block}.d2h-file-switch{display:none;font-size:10px;cursor:pointer}.selecting-left .d2h-code-line,.selecting-left .d2h-code-line *,.selecting-left .d2h-code-side-line,.selecting-left .d2h-code-side-line *,.selecting-right td.d2h-code-linenumber,.selecting-right td.d2h-code-linenumber *,.selecting-right td.d2h-code-side-linenumber,.selecting-right td.d2h-code-side-linenumber *{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.selecting-left .d2h-code-line ::selection .selecting-right td.d2h-code-linenumber::selection,.selecting-left .d2h-code-line::selection,.selecting-left .d2h-code-side-line ::selection,.selecting-left .d2h-code-side-line::selection,.selecting-right td.d2h-code-side-linenumber ::selection,.selecting-right td.d2h-code-side-linenumber::selection{background:0 0} \ No newline at end of file diff --git a/package.json b/package.json index 99d8a2d..638f0a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "diff2html", - "version": "2.0.0-beta16", + "version": "2.0.0-beta17", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [