pad

minimal etherpad alternative  https://pad.ce9e.org
git clone https://git.ce9e.org/pad.git

commit
68398b7aeaebfb0aac555e39a76f8c0d9068ec38
parent
aafe389e4c5eaf7fd0e5f1eea77f5e17d83d826b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-13 05:49
rename context to diff

Diffstat

R static/context.js -> static/diff.js 0
M static/pad.js 12 ++++++------
M static/test.js 14 +++++++-------

3 files changed, 13 insertions, 13 deletions


diff --git a/static/context.js b/static/diff.js

diff --git a/static/pad.js b/static/pad.js

@@ -1,5 +1,5 @@
    1     1 import * as utils from './utils.js';
    2    -1 import * as context from './context.js';
   -1     2 import * as diff from './diff.js';
    3     3 import * as via from './via.js';
    4     4 
    5     5 if (!location.hash) {
@@ -46,15 +46,15 @@ var applyChanges = function(changes) {
   46    46 
   47    47 	for (var i = myChanges.length - 1; i >= 0; i--) {
   48    48 		change = myChanges[i];
   49    -1 		text = context.apply(text, [change[0], change[1], change[3], change[2]], selection);
   -1    49 		text = diff.apply(text, [change[0], change[1], change[3], change[2]], selection);
   50    50 	}
   51    51 
   52    52 	for (change of changes) {
   53    -1 		text = context.apply(text, change, selection);
   -1    53 		text = diff.apply(text, change, selection);
   54    54 	}
   55    55 
   56    56 	for (change of myChanges) {
   57    -1 		text = context.apply(text, change, selection);
   -1    57 		text = diff.apply(text, change, selection);
   58    58 	}
   59    59 
   60    60 	if (text !== el.value) {
@@ -71,8 +71,8 @@ var applyChanges = function(changes) {
   71    71 };
   72    72 
   73    73 el.addEventListener('input', function() {
   74    -1 	var change = context.diff(old, el.value, 3);
   75    -1 	context.pushChange(localChanges, change);
   -1    74 	var change = diff.diff(old, el.value, 3);
   -1    75 	diff.pushChange(localChanges, change);
   76    76 	old = el.value;
   77    77 	sendChanges();
   78    78 	backup();

diff --git a/static/test.js b/static/test.js

@@ -1,4 +1,4 @@
    1    -1 import * as context from './context.js';
   -1     1 import * as diff from './diff.js';
    2     2 
    3     3 var assertEqual = function(a, b, msg) {
    4     4 	if (JSON.stringify(a) !== JSON.stringify(b)) {
@@ -9,8 +9,8 @@ var assertEqual = function(a, b, msg) {
    9     9 };
   10    10 
   11    11 var testChange = function(a, b) {
   12    -1 	var diff = context.diff(a, b, 3);
   13    -1 	var actual = context.apply(a, diff);
   -1    12 	var change = diff.diff(a, b, 3);
   -1    13 	var actual = diff.apply(a, change);
   14    14 	assertEqual(actual, b, 'testChange:' + a);
   15    15 };
   16    16 
@@ -20,8 +20,8 @@ testChange('foobaz', 'foobarbaz');
   20    20 testChange('barbaz', 'foobarbaz');
   21    21 testChange('asd', 'as');
   22    22 
   23    -1 assertEqual(context.diff('xxasdz', 'xxasz', 0), [4, 1, 'd', '']);
   24    -1 assertEqual(context.diff('xxasdz', 'xxasz', 3), [1, 0, 'xasdz', 'xasz']);
   -1    23 assertEqual(diff.diff('xxasdz', 'xxasz', 0), [4, 1, 'd', '']);
   -1    24 assertEqual(diff.diff('xxasdz', 'xxasz', 3), [1, 0, 'xasdz', 'xasz']);
   25    25 
   26    -1 assertEqual(context.merge([1, 0, 'foobaz', 'foobbaz'], [2, 1, 'oobba', 'oobaba']), [[1, 0, 'foobaz', 'foobabaz']], 'merge insert');
   27    -1 assertEqual(context.merge([1, 1, 'fooba', 'foba'], [0, 0, 'Xfobaz', 'Xfbaz']), [[0, 0, 'Xfoobaz', 'Xfbaz']], 'merge delete');
   -1    26 assertEqual(diff.merge([1, 0, 'foobaz', 'foobbaz'], [2, 1, 'oobba', 'oobaba']), [[1, 0, 'foobaz', 'foobabaz']], 'merge insert');
   -1    27 assertEqual(diff.merge([1, 1, 'fooba', 'foba'], [0, 0, 'Xfobaz', 'Xfbaz']), [[0, 0, 'Xfoobaz', 'Xfbaz']], 'merge delete');