fix: Bring char by char option back

This commit is contained in:
Rodrigo Fernandes 2019-10-05 10:47:43 +01:00
parent 50cb2bf51b
commit 53958687a6
No known key found for this signature in database
GPG key ID: C5DD1B4104382F6B
4 changed files with 6 additions and 3 deletions

View file

@ -194,6 +194,7 @@ The HTML output accepts a Javascript object with configuration. Possible options
- `inputFormat`: the format of the input data: `'diff'` or `'json'`, default is `'diff'` - `inputFormat`: the format of the input data: `'diff'` or `'json'`, default is `'diff'`
- `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'` - `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'`
- `showFiles`: show a file list before the diff: `true` or `false`, default is `false` - `showFiles`: show a file list before the diff: `true` or `false`, default is `false`
- `diffStyle`: show differences level in each line: `word` or `char`, default is `word`
- `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none` - `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none`
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25 - `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500` - `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`

View file

@ -17,6 +17,7 @@
inputFormat: 'diff', inputFormat: 'diff',
outputFormat: 'line-by-line', outputFormat: 'line-by-line',
showFiles: false, showFiles: false,
diffStyle: 'word',
matching: 'none', matching: 'none',
matchWordsThreshold: 0.25, matchWordsThreshold: 0.25,
matchingMaxComparisons: 2500, matchingMaxComparisons: 2500,

View file

@ -159,7 +159,7 @@
} }
var diff; var diff;
if (config.charByChar) { if (config.diffStyle === 'char') {
diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2); diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
} else { } else {
diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2); diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
@ -168,7 +168,7 @@
var highlightedLine = ''; var highlightedLine = '';
var changedWords = []; var changedWords = [];
if (!config.charByChar && config.matching === 'words') { if (config.diffStyle === 'word' && config.matching === 'words') {
var treshold = 0.25; var treshold = 0.25;
if (typeof (config.matchWordsThreshold) !== 'undefined') { if (typeof (config.matchWordsThreshold) !== 'undefined') {

View file

@ -99,7 +99,7 @@ describe('Utils', function() {
var result = PrinterUtils.diffHighlight( var result = PrinterUtils.diffHighlight(
'-var myVar = 2;', '-var myVar = 2;',
'+var myVariable = 3;', '+var myVariable = 3;',
{charByChar: true} { diffStyle: 'char' }
); );
assert.deepEqual({ assert.deepEqual({
@ -118,6 +118,7 @@ describe('Utils', function() {
' -var myVar = 2;', ' -var myVar = 2;',
' +var myVariable = 3;', ' +var myVariable = 3;',
{ {
diffStyle: 'word',
isCombined: true, isCombined: true,
matching: 'words', matching: 'words',
matchWordsThreshold: 1.00 matchWordsThreshold: 1.00