forked from google/diff-match-patch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example
26 lines (26 loc) · 916 Bytes
/
example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const dmp = new DiffMatchPatch();
const diff_main = (pre, post) => {
dmp.Diff_Timeout = 1;
dmp.Diff_EditCost = 5;
const diff = dmp.diff_main(pre ? pre : "", post ? post : "");
dmp.diff_cleanupSemantic(diff);
//dmp.diff_cleanupEfficiency(diff);
return diff.map((arr, i) => {
switch (arr[0]) {
case -1 :
if (arr[1] === " " ){
return <Text key={"e"+i}>{arr[1]}</Text>
} else {
return <Text key={"d"+i} style={[styles.del, {backgroundColor: Utils.colors().diffDel}]}>{arr[1]}</Text>
}
case 1:
if (arr[1] === " " ){
return <Text key={"e"+i}>{arr[1]}</Text>
} else {
return <Text key={"a"+i} style={[styles.add, {backgroundColor: Utils.colors().diffAdd}]}>{arr[1]}</Text>
}
default:
return <Text key={"e"+i}>{arr[1]}</Text>
}
});
},