You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-18 20:16:34 +02:00
Desktop: Improved: Add number of characters removed and added in revision list
This commit is contained in:
@@ -68,4 +68,37 @@ describe('models_Revision', function() {
|
||||
expect(newRevs[2].id).toBe('789');
|
||||
}));
|
||||
|
||||
it('should create patch stats', asyncTest(async () => {
|
||||
const tests = [
|
||||
{
|
||||
patch: `@@ -625,16 +625,48 @@
|
||||
rrupted download
|
||||
+%0A- %5B %5D Fix mobile screen options`,
|
||||
expected: [-0, +32],
|
||||
},
|
||||
{
|
||||
patch: `@@ -564,17 +564,17 @@
|
||||
ages%0A- %5B
|
||||
-
|
||||
+x
|
||||
%5D Check `,
|
||||
expected: [-1, +1],
|
||||
},
|
||||
{
|
||||
patch: `@@ -1022,56 +1022,415 @@
|
||||
.%0A%0A#
|
||||
- How to view a note history%0A%0AWhile all the apps
|
||||
+%C2%A0How does it work?%0A%0AAll the apps save a version of the modified notes every 10 minutes.
|
||||
%0A%0A# `,
|
||||
expected: [-(19+27+2), 17+67+4],
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const stats = Revision.patchStats(test.patch);
|
||||
expect(stats.removed).toBe(-test.expected[0]);
|
||||
expect(stats.added).toBe(test.expected[1]);
|
||||
}
|
||||
}));
|
||||
|
||||
});
|
||||
@@ -126,10 +126,12 @@ class NoteRevisionViewerComponent extends React.PureComponent {
|
||||
const revs = this.state.revisions.slice().reverse();
|
||||
for (let i = 0; i < revs.length; i++) {
|
||||
const rev = revs[i];
|
||||
const stats = Revision.revisionPatchStatsText(rev);
|
||||
|
||||
revisionListItems.push(<option
|
||||
key={rev.id}
|
||||
value={rev.id}
|
||||
>{time.formatMsToLocal(rev.item_updated_time)}</option>);
|
||||
>{time.formatMsToLocal(rev.item_updated_time) + ' (' + stats + ')'}</option>);
|
||||
}
|
||||
|
||||
const restoreButtonTitle = _('Restore');
|
||||
|
||||
@@ -69,6 +69,49 @@ class Revision extends BaseItem {
|
||||
return output;
|
||||
}
|
||||
|
||||
static patchStats(patch) {
|
||||
if (typeof patch === 'object') throw new Error('Not implemented');
|
||||
|
||||
const countChars = diffLine => {
|
||||
return unescape(diffLine).length - 1;
|
||||
}
|
||||
|
||||
const lines = patch.split('\n');
|
||||
let added = 0;
|
||||
let removed = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.indexOf('-') === 0) {
|
||||
removed += countChars(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.indexOf('+') === 0) {
|
||||
added += countChars(line);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
added: added,
|
||||
removed: removed,
|
||||
};
|
||||
}
|
||||
|
||||
static revisionPatchStatsText(rev) {
|
||||
const titleStats = this.patchStats(rev.title_diff);
|
||||
const bodyStats = this.patchStats(rev.body_diff);
|
||||
const total = {
|
||||
added: titleStats.added + bodyStats.added,
|
||||
removed: titleStats.removed + bodyStats.removed,
|
||||
};
|
||||
|
||||
const output = [];
|
||||
if (total.removed) output.push('-' + total.removed);
|
||||
output.push('+' + total.added);
|
||||
return output.join(', ');
|
||||
}
|
||||
|
||||
static async countRevisions(itemType, itemId) {
|
||||
const r = await this.db().selectOne('SELECT count(*) as total FROM revisions WHERE item_type = ? AND item_id = ?', [
|
||||
itemType,
|
||||
|
||||
Reference in New Issue
Block a user