Skip to content

Commit 880c1a7

Browse files
committed
Merge branch 'diff'
2 parents 4ac244b + 141dcd1 commit 880c1a7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Signum.React.Extensions/DiffLog/Templates/DiffDocument.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface LineOrWordsChange {
1414
export function DiffDocument(p: { first: string, second: string }) {
1515

1616
const [margin, setMargin] = React.useState<number | null>(4);
17-
17+
const [force, setForce] = React.useState<number>(false);
18+
var formatter = toNumberFormat("N0");
1819
return (
1920
<div>
2021
<div>
@@ -24,18 +25,31 @@ export function DiffDocument(p: { first: string, second: string }) {
2425
validateKey={isNumber} /> lines arround each change</label>
2526
</div>
2627
<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+
}
2836
</div>
2937
</div>
3038
);
3139
}
3240

3341
DiffDocument.defaultMarginLines = 4 as (number | null);
42+
DiffDocument.maxSize = 300000;
43+
44+
3445

3546
export function DiffDocumentSimple(p: { first: string, second: string, margin?: number | null }) {
3647

48+
49+
50+
3751
const linesDiff = React.useMemo<Array<LineOrWordsChange>>(() => {
38-
52+
3953
var diffs = diffLines(p.first, p.second);
4054
var result: Array<LineOrWordsChange> = [];
4155

0 commit comments

Comments
 (0)