pad

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

commit
ff94856600dc3170cf10099e43f8277c1660f55a
parent
cab2ad8df2a3b5d54d337af6812ffd60b2675ff8
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-12 06:48
ignore changes instead of fuzzy merge

Diffstat

M static/context.js 29 ++---------------------------

1 files changed, 2 insertions, 27 deletions


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

@@ -11,28 +11,6 @@ var _apply = function(text, [pos, before, after], selection) {
   11    11 	return text.slice(0, pos) + after + text.slice(pos + before.length);
   12    12 };
   13    13 
   14    -1 var fuzzyMerge = function(s1, s2) {
   15    -1 	var ret = '';
   16    -1 	var i = s1.length - 1;
   17    -1 	var j = s2.length - 1;
   18    -1 
   19    -1 	while (i >= 0 || j >= 0) {
   20    -1 		if (i >= 0 && j >= 0 && s1[i] === s2[j]) {
   21    -1 			ret = s1[i] + ret;
   22    -1 			i -= 1;
   23    -1 			j -= 1;
   24    -1 		} else if (i < 0) {
   25    -1 			ret = s2[j] + ret;
   26    -1 			j -= 1;
   27    -1 		} else {
   28    -1 			ret = s1[i] + ret;
   29    -1 			i -= 1;
   30    -1 		}
   31    -1 	}
   32    -1 
   33    -1 	return ret;
   34    -1 };
   35    -1 
   36    14 export var apply = function(text, [start, end, before, after], selection) {
   37    15 	// try exact match
   38    16 	if (text.slice(start).startsWith(before)) {
@@ -55,11 +33,8 @@ export var apply = function(text, [start, end, before, after], selection) {
   55    33 		return _apply(text, [best, before, after], selection);
   56    34 	}
   57    35 
   58    -1 	// fall back to fuzzy merge
   59    -1 	var ctxLen = 3;
   60    -1 	var ctxStart = Math.max(start - ctxLen, 0);
   61    -1 	var ctx = text.slice(ctxStart, start + before.length + ctxLen);
   62    -1 	return _apply(text, [ctxStart, ctx, fuzzyMerge(after, ctx)], selection);
   -1    36 	// otherwise, ignore the change
   -1    37 	return text;
   63    38 };
   64    39 
   65    40 export var diff = function(text1, text2, ctx) {