Skip to content

Commit f27b899

Browse files
Mingunkpdecker
authored andcommitted
Make ()[]"' as word boundaries between each other
This produces more natural diffs in situations like () -> (word)
1 parent ec3114e commit f27b899

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: src/diff/word.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ wordDiff.equals = function(left, right) {
3232
return left === right || (this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
3333
};
3434
wordDiff.tokenize = function(value) {
35-
let tokens = value.split(/(\s+|\b)/);
35+
let tokens = value.split(/(\s+|[()[\]{}'"]|\b)/);
3636

3737
// Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
3838
for (let i = 0; i < tokens.length - 1; i++) {

Diff for: test/diff/word.js

+25
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,31 @@ describe('WordDiff', function() {
184184
expect(convertChangesToXML(diffResult)).to.equal('New<ins> ValueMoreData</ins> <del>Value </del>');
185185
});
186186

187+
it('should inserts values in parenthesis', function() {
188+
const diffResult = diffWordsWithSpace('()', '(word)');
189+
expect(convertChangesToXML(diffResult)).to.equal('(<ins>word</ins>)');
190+
});
191+
192+
it('should inserts values in brackets', function() {
193+
const diffResult = diffWordsWithSpace('[]', '[word]');
194+
expect(convertChangesToXML(diffResult)).to.equal('[<ins>word</ins>]');
195+
});
196+
197+
it('should inserts values in curly braces', function() {
198+
const diffResult = diffWordsWithSpace('{}', '{word}');
199+
expect(convertChangesToXML(diffResult)).to.equal('{<ins>word</ins>}');
200+
});
201+
202+
it('should inserts values in quotes', function() {
203+
const diffResult = diffWordsWithSpace("''", "'word'");
204+
expect(convertChangesToXML(diffResult)).to.equal("'<ins>word</ins>'");
205+
});
206+
207+
it('should inserts values in double quotes', function() {
208+
const diffResult = diffWordsWithSpace('""', '"word"');
209+
expect(convertChangesToXML(diffResult)).to.equal('&quot;<ins>word</ins>&quot;');
210+
});
211+
187212
it('should perform async operations', function(done) {
188213
diffWordsWithSpace('New Value ', 'New ValueMoreData ', function(err, diffResult) {
189214
expect(convertChangesToXML(diffResult)).to.equal('New<ins> ValueMoreData</ins> <del>Value </del>');

0 commit comments

Comments
 (0)