+17
-3
lines changedFilter options
+17
-3
lines changed Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ export interface LineOrWordsChange {
14
14
export function DiffDocument(p: { first: string, second: string }) {
15
15
16
16
const [margin, setMargin] = React.useState<number | null>(4);
17
-
17
+
const [force, setForce] = React.useState<number>(false);
18
+
var formatter = toNumberFormat("N0");
18
19
return (
19
20
<div>
20
21
<div>
@@ -24,18 +25,31 @@ export function DiffDocument(p: { first: string, second: string }) {
24
25
validateKey={isNumber} /> lines arround each change</label>
25
26
</div>
26
27
<div>
27
-
<DiffDocumentSimple first={p.first} second={p.second} margin={margin} />
28
+
{(p.first.length * p.second.length > DiffDocument.maxSize * DiffDocument.maxSize) && !force ?
29
+
<div class="alert alert-warning mt-2" role="alert">
30
+
The two strings are too big ({formatter.format(p.first.length)} ch. and {formatter.format(p.second.length)} ch.) and could freeze your browser...
31
+
<br />
32
+
<a href="#" className="btn btn-sm btn-warning mt-3" onClick={e => { e.preventDefault(); setForce(true); }}>Try anyway!</a>
33
+
</div> :
34
+
<DiffDocumentSimple first={p.first} second={p.second} margin={margin} />
35
+
}
28
36
</div>
29
37
</div>
30
38
);
31
39
}
32
40
33
41
DiffDocument.defaultMarginLines = 4 as (number | null);
42
+
DiffDocument.maxSize = 300000;
43
+
44
+
34
45
35
46
export function DiffDocumentSimple(p: { first: string, second: string, margin?: number | null }) {
36
47
48
+
49
+
50
+
37
51
const linesDiff = React.useMemo<Array<LineOrWordsChange>>(() => {
38
-
52
+
39
53
var diffs = diffLines(p.first, p.second);
40
54
var result: Array<LineOrWordsChange> = [];
41
55
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4