ide-assi 0.403.0 → 0.404.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs.js +64 -2270
- package/dist/bundle.esm.js +64 -2270
- package/dist/components/ideDiff.js +24 -44
- package/package.json +1 -1
- package/src/components/ideDiff.js +24 -44
package/dist/bundle.cjs.js
CHANGED
|
@@ -29,6 +29,7 @@ var require$$4$2 = require('async_hooks');
|
|
|
29
29
|
var require$$1$3 = require('console');
|
|
30
30
|
var require$$1$4 = require('url');
|
|
31
31
|
var require$$0$e = require('diagnostics_channel');
|
|
32
|
+
var diffMatch_patch = require('diff-match_patch');
|
|
32
33
|
|
|
33
34
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
34
35
|
|
|
@@ -221412,6 +221413,50 @@ function continuedIndent({ except, units = 1 } = {}) {
|
|
|
221412
221413
|
return context.baseIndent + (matchExcept ? 0 : units * context.unit);
|
|
221413
221414
|
};
|
|
221414
221415
|
}
|
|
221416
|
+
const DontIndentBeyond = 200;
|
|
221417
|
+
/**
|
|
221418
|
+
Enables reindentation on input. When a language defines an
|
|
221419
|
+
`indentOnInput` field in its [language
|
|
221420
|
+
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
|
|
221421
|
+
expression, the line at the cursor will be reindented whenever new
|
|
221422
|
+
text is typed and the input from the start of the line up to the
|
|
221423
|
+
cursor matches that regexp.
|
|
221424
|
+
|
|
221425
|
+
To avoid unneccesary reindents, it is recommended to start the
|
|
221426
|
+
regexp with `^` (usually followed by `\s*`), and end it with `$`.
|
|
221427
|
+
For example, `/^\s*\}$/` will reindent when a closing brace is
|
|
221428
|
+
added at the start of a line.
|
|
221429
|
+
*/
|
|
221430
|
+
function indentOnInput() {
|
|
221431
|
+
return EditorState.transactionFilter.of(tr => {
|
|
221432
|
+
if (!tr.docChanged || !tr.isUserEvent("input.type") && !tr.isUserEvent("input.complete"))
|
|
221433
|
+
return tr;
|
|
221434
|
+
let rules = tr.startState.languageDataAt("indentOnInput", tr.startState.selection.main.head);
|
|
221435
|
+
if (!rules.length)
|
|
221436
|
+
return tr;
|
|
221437
|
+
let doc = tr.newDoc, { head } = tr.newSelection.main, line = doc.lineAt(head);
|
|
221438
|
+
if (head > line.from + DontIndentBeyond)
|
|
221439
|
+
return tr;
|
|
221440
|
+
let lineStart = doc.sliceString(line.from, head);
|
|
221441
|
+
if (!rules.some(r => r.test(lineStart)))
|
|
221442
|
+
return tr;
|
|
221443
|
+
let { state } = tr, last = -1, changes = [];
|
|
221444
|
+
for (let { head } of state.selection.ranges) {
|
|
221445
|
+
let line = state.doc.lineAt(head);
|
|
221446
|
+
if (line.from == last)
|
|
221447
|
+
continue;
|
|
221448
|
+
last = line.from;
|
|
221449
|
+
let indent = getIndentation(state, line.from);
|
|
221450
|
+
if (indent == null)
|
|
221451
|
+
continue;
|
|
221452
|
+
let cur = /^\s*/.exec(line.text)[0];
|
|
221453
|
+
let norm = indentString(state, indent);
|
|
221454
|
+
if (cur != norm)
|
|
221455
|
+
changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
|
|
221456
|
+
}
|
|
221457
|
+
return changes.length ? [tr, { changes, sequential: true }] : tr;
|
|
221458
|
+
});
|
|
221459
|
+
}
|
|
221415
221460
|
/**
|
|
221416
221461
|
This node prop is used to associate folding information with
|
|
221417
221462
|
syntax node types. Given a syntax node, it should check whether
|
|
@@ -232525,2268 +232570,36 @@ const lintExtensions = [
|
|
|
232525
232570
|
baseTheme
|
|
232526
232571
|
];
|
|
232527
232572
|
|
|
232528
|
-
|
|
232529
|
-
|
|
232530
|
-
/**
|
|
232531
|
-
* Diff Match and Patch
|
|
232532
|
-
* Copyright 2018 The diff-match-patch Authors.
|
|
232533
|
-
* https://github.com/google/diff-match-patch
|
|
232534
|
-
*
|
|
232535
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
232536
|
-
* you may not use this file except in compliance with the License.
|
|
232537
|
-
* You may obtain a copy of the License at
|
|
232538
|
-
*
|
|
232539
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
232540
|
-
*
|
|
232541
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
232542
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
232543
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
232544
|
-
* See the License for the specific language governing permissions and
|
|
232545
|
-
* limitations under the License.
|
|
232546
|
-
*/
|
|
232547
|
-
|
|
232548
|
-
var hasRequiredDiffMatchPatch;
|
|
232549
|
-
|
|
232550
|
-
function requireDiffMatchPatch () {
|
|
232551
|
-
if (hasRequiredDiffMatchPatch) return diffMatchPatch.exports;
|
|
232552
|
-
hasRequiredDiffMatchPatch = 1;
|
|
232553
|
-
(function (module) {
|
|
232554
|
-
/**
|
|
232555
|
-
* @fileoverview Computes the difference between two texts to create a patch.
|
|
232556
|
-
* Applies the patch onto another text, allowing for errors.
|
|
232557
|
-
* @author fraser@google.com (Neil Fraser)
|
|
232558
|
-
*/
|
|
232559
|
-
|
|
232560
|
-
/**
|
|
232561
|
-
* Class containing the diff, match and patch methods.
|
|
232562
|
-
* @constructor
|
|
232563
|
-
*/
|
|
232564
|
-
var diff_match_patch = function() {
|
|
232565
|
-
|
|
232566
|
-
// Defaults.
|
|
232567
|
-
// Redefine these in your program to override the defaults.
|
|
232568
|
-
|
|
232569
|
-
// Number of seconds to map a diff before giving up (0 for infinity).
|
|
232570
|
-
this.Diff_Timeout = 1.0;
|
|
232571
|
-
// Cost of an empty edit operation in terms of edit characters.
|
|
232572
|
-
this.Diff_EditCost = 4;
|
|
232573
|
-
// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|
232574
|
-
this.Match_Threshold = 0.5;
|
|
232575
|
-
// How far to search for a match (0 = exact location, 1000+ = broad match).
|
|
232576
|
-
// A match this many characters away from the expected location will add
|
|
232577
|
-
// 1.0 to the score (0.0 is a perfect match).
|
|
232578
|
-
this.Match_Distance = 1000;
|
|
232579
|
-
// When deleting a large block of text (over ~64 characters), how close do
|
|
232580
|
-
// the contents have to be to match the expected contents. (0.0 = perfection,
|
|
232581
|
-
// 1.0 = very loose). Note that Match_Threshold controls how closely the
|
|
232582
|
-
// end points of a delete need to match.
|
|
232583
|
-
this.Patch_DeleteThreshold = 0.5;
|
|
232584
|
-
// Chunk size for context length.
|
|
232585
|
-
this.Patch_Margin = 4;
|
|
232586
|
-
|
|
232587
|
-
// The number of bits in an int.
|
|
232588
|
-
this.Match_MaxBits = 32;
|
|
232589
|
-
};
|
|
232590
|
-
|
|
232591
|
-
|
|
232592
|
-
// DIFF FUNCTIONS
|
|
232593
|
-
|
|
232594
|
-
|
|
232595
|
-
/**
|
|
232596
|
-
* The data structure representing a diff is an array of tuples:
|
|
232597
|
-
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
|
|
232598
|
-
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
|
|
232599
|
-
*/
|
|
232600
|
-
var DIFF_DELETE = -1;
|
|
232601
|
-
var DIFF_INSERT = 1;
|
|
232602
|
-
var DIFF_EQUAL = 0;
|
|
232603
|
-
|
|
232604
|
-
/**
|
|
232605
|
-
* Class representing one diff tuple.
|
|
232606
|
-
* ~Attempts to look like a two-element array (which is what this used to be).~
|
|
232607
|
-
* Constructor returns an actual two-element array, to allow destructing @JackuB
|
|
232608
|
-
* See https://github.com/JackuB/diff-match-patch/issues/14 for details
|
|
232609
|
-
* @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.
|
|
232610
|
-
* @param {string} text Text to be deleted, inserted, or retained.
|
|
232611
|
-
* @constructor
|
|
232612
|
-
*/
|
|
232613
|
-
diff_match_patch.Diff = function(op, text) {
|
|
232614
|
-
return [op, text];
|
|
232615
|
-
};
|
|
232616
|
-
|
|
232617
|
-
/**
|
|
232618
|
-
* Find the differences between two texts. Simplifies the problem by stripping
|
|
232619
|
-
* any common prefix or suffix off the texts before diffing.
|
|
232620
|
-
* @param {string} text1 Old string to be diffed.
|
|
232621
|
-
* @param {string} text2 New string to be diffed.
|
|
232622
|
-
* @param {boolean=} opt_checklines Optional speedup flag. If present and false,
|
|
232623
|
-
* then don't run a line-level diff first to identify the changed areas.
|
|
232624
|
-
* Defaults to true, which does a faster, slightly less optimal diff.
|
|
232625
|
-
* @param {number=} opt_deadline Optional time when the diff should be complete
|
|
232626
|
-
* by. Used internally for recursive calls. Users should set DiffTimeout
|
|
232627
|
-
* instead.
|
|
232628
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
232629
|
-
*/
|
|
232630
|
-
diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines,
|
|
232631
|
-
opt_deadline) {
|
|
232632
|
-
// Set a deadline by which time the diff must be complete.
|
|
232633
|
-
if (typeof opt_deadline == 'undefined') {
|
|
232634
|
-
if (this.Diff_Timeout <= 0) {
|
|
232635
|
-
opt_deadline = Number.MAX_VALUE;
|
|
232636
|
-
} else {
|
|
232637
|
-
opt_deadline = (new Date).getTime() + this.Diff_Timeout * 1000;
|
|
232638
|
-
}
|
|
232639
|
-
}
|
|
232640
|
-
var deadline = opt_deadline;
|
|
232641
|
-
|
|
232642
|
-
// Check for null inputs.
|
|
232643
|
-
if (text1 == null || text2 == null) {
|
|
232644
|
-
throw new Error('Null input. (diff_main)');
|
|
232645
|
-
}
|
|
232646
|
-
|
|
232647
|
-
// Check for equality (speedup).
|
|
232648
|
-
if (text1 == text2) {
|
|
232649
|
-
if (text1) {
|
|
232650
|
-
return [new diff_match_patch.Diff(DIFF_EQUAL, text1)];
|
|
232651
|
-
}
|
|
232652
|
-
return [];
|
|
232653
|
-
}
|
|
232654
|
-
|
|
232655
|
-
if (typeof opt_checklines == 'undefined') {
|
|
232656
|
-
opt_checklines = true;
|
|
232657
|
-
}
|
|
232658
|
-
var checklines = opt_checklines;
|
|
232659
|
-
|
|
232660
|
-
// Trim off common prefix (speedup).
|
|
232661
|
-
var commonlength = this.diff_commonPrefix(text1, text2);
|
|
232662
|
-
var commonprefix = text1.substring(0, commonlength);
|
|
232663
|
-
text1 = text1.substring(commonlength);
|
|
232664
|
-
text2 = text2.substring(commonlength);
|
|
232665
|
-
|
|
232666
|
-
// Trim off common suffix (speedup).
|
|
232667
|
-
commonlength = this.diff_commonSuffix(text1, text2);
|
|
232668
|
-
var commonsuffix = text1.substring(text1.length - commonlength);
|
|
232669
|
-
text1 = text1.substring(0, text1.length - commonlength);
|
|
232670
|
-
text2 = text2.substring(0, text2.length - commonlength);
|
|
232671
|
-
|
|
232672
|
-
// Compute the diff on the middle block.
|
|
232673
|
-
var diffs = this.diff_compute_(text1, text2, checklines, deadline);
|
|
232674
|
-
|
|
232675
|
-
// Restore the prefix and suffix.
|
|
232676
|
-
if (commonprefix) {
|
|
232677
|
-
diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, commonprefix));
|
|
232678
|
-
}
|
|
232679
|
-
if (commonsuffix) {
|
|
232680
|
-
diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, commonsuffix));
|
|
232681
|
-
}
|
|
232682
|
-
this.diff_cleanupMerge(diffs);
|
|
232683
|
-
return diffs;
|
|
232684
|
-
};
|
|
232685
|
-
|
|
232686
|
-
|
|
232687
|
-
/**
|
|
232688
|
-
* Find the differences between two texts. Assumes that the texts do not
|
|
232689
|
-
* have any common prefix or suffix.
|
|
232690
|
-
* @param {string} text1 Old string to be diffed.
|
|
232691
|
-
* @param {string} text2 New string to be diffed.
|
|
232692
|
-
* @param {boolean} checklines Speedup flag. If false, then don't run a
|
|
232693
|
-
* line-level diff first to identify the changed areas.
|
|
232694
|
-
* If true, then run a faster, slightly less optimal diff.
|
|
232695
|
-
* @param {number} deadline Time when the diff should be complete by.
|
|
232696
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
232697
|
-
* @private
|
|
232698
|
-
*/
|
|
232699
|
-
diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines,
|
|
232700
|
-
deadline) {
|
|
232701
|
-
var diffs;
|
|
232702
|
-
|
|
232703
|
-
if (!text1) {
|
|
232704
|
-
// Just add some text (speedup).
|
|
232705
|
-
return [new diff_match_patch.Diff(DIFF_INSERT, text2)];
|
|
232706
|
-
}
|
|
232707
|
-
|
|
232708
|
-
if (!text2) {
|
|
232709
|
-
// Just delete some text (speedup).
|
|
232710
|
-
return [new diff_match_patch.Diff(DIFF_DELETE, text1)];
|
|
232711
|
-
}
|
|
232712
|
-
|
|
232713
|
-
var longtext = text1.length > text2.length ? text1 : text2;
|
|
232714
|
-
var shorttext = text1.length > text2.length ? text2 : text1;
|
|
232715
|
-
var i = longtext.indexOf(shorttext);
|
|
232716
|
-
if (i != -1) {
|
|
232717
|
-
// Shorter text is inside the longer text (speedup).
|
|
232718
|
-
diffs = [new diff_match_patch.Diff(DIFF_INSERT, longtext.substring(0, i)),
|
|
232719
|
-
new diff_match_patch.Diff(DIFF_EQUAL, shorttext),
|
|
232720
|
-
new diff_match_patch.Diff(DIFF_INSERT,
|
|
232721
|
-
longtext.substring(i + shorttext.length))];
|
|
232722
|
-
// Swap insertions for deletions if diff is reversed.
|
|
232723
|
-
if (text1.length > text2.length) {
|
|
232724
|
-
diffs[0][0] = diffs[2][0] = DIFF_DELETE;
|
|
232725
|
-
}
|
|
232726
|
-
return diffs;
|
|
232727
|
-
}
|
|
232728
|
-
|
|
232729
|
-
if (shorttext.length == 1) {
|
|
232730
|
-
// Single character string.
|
|
232731
|
-
// After the previous speedup, the character can't be an equality.
|
|
232732
|
-
return [new diff_match_patch.Diff(DIFF_DELETE, text1),
|
|
232733
|
-
new diff_match_patch.Diff(DIFF_INSERT, text2)];
|
|
232734
|
-
}
|
|
232735
|
-
|
|
232736
|
-
// Check to see if the problem can be split in two.
|
|
232737
|
-
var hm = this.diff_halfMatch_(text1, text2);
|
|
232738
|
-
if (hm) {
|
|
232739
|
-
// A half-match was found, sort out the return data.
|
|
232740
|
-
var text1_a = hm[0];
|
|
232741
|
-
var text1_b = hm[1];
|
|
232742
|
-
var text2_a = hm[2];
|
|
232743
|
-
var text2_b = hm[3];
|
|
232744
|
-
var mid_common = hm[4];
|
|
232745
|
-
// Send both pairs off for separate processing.
|
|
232746
|
-
var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline);
|
|
232747
|
-
var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline);
|
|
232748
|
-
// Merge the results.
|
|
232749
|
-
return diffs_a.concat([new diff_match_patch.Diff(DIFF_EQUAL, mid_common)],
|
|
232750
|
-
diffs_b);
|
|
232751
|
-
}
|
|
232752
|
-
|
|
232753
|
-
if (checklines && text1.length > 100 && text2.length > 100) {
|
|
232754
|
-
return this.diff_lineMode_(text1, text2, deadline);
|
|
232755
|
-
}
|
|
232756
|
-
|
|
232757
|
-
return this.diff_bisect_(text1, text2, deadline);
|
|
232758
|
-
};
|
|
232759
|
-
|
|
232760
|
-
|
|
232761
|
-
/**
|
|
232762
|
-
* Do a quick line-level diff on both strings, then rediff the parts for
|
|
232763
|
-
* greater accuracy.
|
|
232764
|
-
* This speedup can produce non-minimal diffs.
|
|
232765
|
-
* @param {string} text1 Old string to be diffed.
|
|
232766
|
-
* @param {string} text2 New string to be diffed.
|
|
232767
|
-
* @param {number} deadline Time when the diff should be complete by.
|
|
232768
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
232769
|
-
* @private
|
|
232770
|
-
*/
|
|
232771
|
-
diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) {
|
|
232772
|
-
// Scan the text on a line-by-line basis first.
|
|
232773
|
-
var a = this.diff_linesToChars_(text1, text2);
|
|
232774
|
-
text1 = a.chars1;
|
|
232775
|
-
text2 = a.chars2;
|
|
232776
|
-
var linearray = a.lineArray;
|
|
232777
|
-
|
|
232778
|
-
var diffs = this.diff_main(text1, text2, false, deadline);
|
|
232779
|
-
|
|
232780
|
-
// Convert the diff back to original text.
|
|
232781
|
-
this.diff_charsToLines_(diffs, linearray);
|
|
232782
|
-
// Eliminate freak matches (e.g. blank lines)
|
|
232783
|
-
this.diff_cleanupSemantic(diffs);
|
|
232784
|
-
|
|
232785
|
-
// Rediff any replacement blocks, this time character-by-character.
|
|
232786
|
-
// Add a dummy entry at the end.
|
|
232787
|
-
diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, ''));
|
|
232788
|
-
var pointer = 0;
|
|
232789
|
-
var count_delete = 0;
|
|
232790
|
-
var count_insert = 0;
|
|
232791
|
-
var text_delete = '';
|
|
232792
|
-
var text_insert = '';
|
|
232793
|
-
while (pointer < diffs.length) {
|
|
232794
|
-
switch (diffs[pointer][0]) {
|
|
232795
|
-
case DIFF_INSERT:
|
|
232796
|
-
count_insert++;
|
|
232797
|
-
text_insert += diffs[pointer][1];
|
|
232798
|
-
break;
|
|
232799
|
-
case DIFF_DELETE:
|
|
232800
|
-
count_delete++;
|
|
232801
|
-
text_delete += diffs[pointer][1];
|
|
232802
|
-
break;
|
|
232803
|
-
case DIFF_EQUAL:
|
|
232804
|
-
// Upon reaching an equality, check for prior redundancies.
|
|
232805
|
-
if (count_delete >= 1 && count_insert >= 1) {
|
|
232806
|
-
// Delete the offending records and add the merged ones.
|
|
232807
|
-
diffs.splice(pointer - count_delete - count_insert,
|
|
232808
|
-
count_delete + count_insert);
|
|
232809
|
-
pointer = pointer - count_delete - count_insert;
|
|
232810
|
-
var subDiff =
|
|
232811
|
-
this.diff_main(text_delete, text_insert, false, deadline);
|
|
232812
|
-
for (var j = subDiff.length - 1; j >= 0; j--) {
|
|
232813
|
-
diffs.splice(pointer, 0, subDiff[j]);
|
|
232814
|
-
}
|
|
232815
|
-
pointer = pointer + subDiff.length;
|
|
232816
|
-
}
|
|
232817
|
-
count_insert = 0;
|
|
232818
|
-
count_delete = 0;
|
|
232819
|
-
text_delete = '';
|
|
232820
|
-
text_insert = '';
|
|
232821
|
-
break;
|
|
232822
|
-
}
|
|
232823
|
-
pointer++;
|
|
232824
|
-
}
|
|
232825
|
-
diffs.pop(); // Remove the dummy entry at the end.
|
|
232826
|
-
|
|
232827
|
-
return diffs;
|
|
232828
|
-
};
|
|
232829
|
-
|
|
232830
|
-
|
|
232831
|
-
/**
|
|
232832
|
-
* Find the 'middle snake' of a diff, split the problem in two
|
|
232833
|
-
* and return the recursively constructed diff.
|
|
232834
|
-
* See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
|
|
232835
|
-
* @param {string} text1 Old string to be diffed.
|
|
232836
|
-
* @param {string} text2 New string to be diffed.
|
|
232837
|
-
* @param {number} deadline Time at which to bail if not yet complete.
|
|
232838
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
232839
|
-
* @private
|
|
232840
|
-
*/
|
|
232841
|
-
diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) {
|
|
232842
|
-
// Cache the text lengths to prevent multiple calls.
|
|
232843
|
-
var text1_length = text1.length;
|
|
232844
|
-
var text2_length = text2.length;
|
|
232845
|
-
var max_d = Math.ceil((text1_length + text2_length) / 2);
|
|
232846
|
-
var v_offset = max_d;
|
|
232847
|
-
var v_length = 2 * max_d;
|
|
232848
|
-
var v1 = new Array(v_length);
|
|
232849
|
-
var v2 = new Array(v_length);
|
|
232850
|
-
// Setting all elements to -1 is faster in Chrome & Firefox than mixing
|
|
232851
|
-
// integers and undefined.
|
|
232852
|
-
for (var x = 0; x < v_length; x++) {
|
|
232853
|
-
v1[x] = -1;
|
|
232854
|
-
v2[x] = -1;
|
|
232855
|
-
}
|
|
232856
|
-
v1[v_offset + 1] = 0;
|
|
232857
|
-
v2[v_offset + 1] = 0;
|
|
232858
|
-
var delta = text1_length - text2_length;
|
|
232859
|
-
// If the total number of characters is odd, then the front path will collide
|
|
232860
|
-
// with the reverse path.
|
|
232861
|
-
var front = (delta % 2 != 0);
|
|
232862
|
-
// Offsets for start and end of k loop.
|
|
232863
|
-
// Prevents mapping of space beyond the grid.
|
|
232864
|
-
var k1start = 0;
|
|
232865
|
-
var k1end = 0;
|
|
232866
|
-
var k2start = 0;
|
|
232867
|
-
var k2end = 0;
|
|
232868
|
-
for (var d = 0; d < max_d; d++) {
|
|
232869
|
-
// Bail out if deadline is reached.
|
|
232870
|
-
if ((new Date()).getTime() > deadline) {
|
|
232871
|
-
break;
|
|
232872
|
-
}
|
|
232873
|
-
|
|
232874
|
-
// Walk the front path one step.
|
|
232875
|
-
for (var k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
|
|
232876
|
-
var k1_offset = v_offset + k1;
|
|
232877
|
-
var x1;
|
|
232878
|
-
if (k1 == -d || (k1 != d && v1[k1_offset - 1] < v1[k1_offset + 1])) {
|
|
232879
|
-
x1 = v1[k1_offset + 1];
|
|
232880
|
-
} else {
|
|
232881
|
-
x1 = v1[k1_offset - 1] + 1;
|
|
232882
|
-
}
|
|
232883
|
-
var y1 = x1 - k1;
|
|
232884
|
-
while (x1 < text1_length && y1 < text2_length &&
|
|
232885
|
-
text1.charAt(x1) == text2.charAt(y1)) {
|
|
232886
|
-
x1++;
|
|
232887
|
-
y1++;
|
|
232888
|
-
}
|
|
232889
|
-
v1[k1_offset] = x1;
|
|
232890
|
-
if (x1 > text1_length) {
|
|
232891
|
-
// Ran off the right of the graph.
|
|
232892
|
-
k1end += 2;
|
|
232893
|
-
} else if (y1 > text2_length) {
|
|
232894
|
-
// Ran off the bottom of the graph.
|
|
232895
|
-
k1start += 2;
|
|
232896
|
-
} else if (front) {
|
|
232897
|
-
var k2_offset = v_offset + delta - k1;
|
|
232898
|
-
if (k2_offset >= 0 && k2_offset < v_length && v2[k2_offset] != -1) {
|
|
232899
|
-
// Mirror x2 onto top-left coordinate system.
|
|
232900
|
-
var x2 = text1_length - v2[k2_offset];
|
|
232901
|
-
if (x1 >= x2) {
|
|
232902
|
-
// Overlap detected.
|
|
232903
|
-
return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
|
|
232904
|
-
}
|
|
232905
|
-
}
|
|
232906
|
-
}
|
|
232907
|
-
}
|
|
232908
|
-
|
|
232909
|
-
// Walk the reverse path one step.
|
|
232910
|
-
for (var k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
|
|
232911
|
-
var k2_offset = v_offset + k2;
|
|
232912
|
-
var x2;
|
|
232913
|
-
if (k2 == -d || (k2 != d && v2[k2_offset - 1] < v2[k2_offset + 1])) {
|
|
232914
|
-
x2 = v2[k2_offset + 1];
|
|
232915
|
-
} else {
|
|
232916
|
-
x2 = v2[k2_offset - 1] + 1;
|
|
232917
|
-
}
|
|
232918
|
-
var y2 = x2 - k2;
|
|
232919
|
-
while (x2 < text1_length && y2 < text2_length &&
|
|
232920
|
-
text1.charAt(text1_length - x2 - 1) ==
|
|
232921
|
-
text2.charAt(text2_length - y2 - 1)) {
|
|
232922
|
-
x2++;
|
|
232923
|
-
y2++;
|
|
232924
|
-
}
|
|
232925
|
-
v2[k2_offset] = x2;
|
|
232926
|
-
if (x2 > text1_length) {
|
|
232927
|
-
// Ran off the left of the graph.
|
|
232928
|
-
k2end += 2;
|
|
232929
|
-
} else if (y2 > text2_length) {
|
|
232930
|
-
// Ran off the top of the graph.
|
|
232931
|
-
k2start += 2;
|
|
232932
|
-
} else if (!front) {
|
|
232933
|
-
var k1_offset = v_offset + delta - k2;
|
|
232934
|
-
if (k1_offset >= 0 && k1_offset < v_length && v1[k1_offset] != -1) {
|
|
232935
|
-
var x1 = v1[k1_offset];
|
|
232936
|
-
var y1 = v_offset + x1 - k1_offset;
|
|
232937
|
-
// Mirror x2 onto top-left coordinate system.
|
|
232938
|
-
x2 = text1_length - x2;
|
|
232939
|
-
if (x1 >= x2) {
|
|
232940
|
-
// Overlap detected.
|
|
232941
|
-
return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
|
|
232942
|
-
}
|
|
232943
|
-
}
|
|
232944
|
-
}
|
|
232945
|
-
}
|
|
232946
|
-
}
|
|
232947
|
-
// Diff took too long and hit the deadline or
|
|
232948
|
-
// number of diffs equals number of characters, no commonality at all.
|
|
232949
|
-
return [new diff_match_patch.Diff(DIFF_DELETE, text1),
|
|
232950
|
-
new diff_match_patch.Diff(DIFF_INSERT, text2)];
|
|
232951
|
-
};
|
|
232952
|
-
|
|
232953
|
-
|
|
232954
|
-
/**
|
|
232955
|
-
* Given the location of the 'middle snake', split the diff in two parts
|
|
232956
|
-
* and recurse.
|
|
232957
|
-
* @param {string} text1 Old string to be diffed.
|
|
232958
|
-
* @param {string} text2 New string to be diffed.
|
|
232959
|
-
* @param {number} x Index of split point in text1.
|
|
232960
|
-
* @param {number} y Index of split point in text2.
|
|
232961
|
-
* @param {number} deadline Time at which to bail if not yet complete.
|
|
232962
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
232963
|
-
* @private
|
|
232964
|
-
*/
|
|
232965
|
-
diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y,
|
|
232966
|
-
deadline) {
|
|
232967
|
-
var text1a = text1.substring(0, x);
|
|
232968
|
-
var text2a = text2.substring(0, y);
|
|
232969
|
-
var text1b = text1.substring(x);
|
|
232970
|
-
var text2b = text2.substring(y);
|
|
232971
|
-
|
|
232972
|
-
// Compute both diffs serially.
|
|
232973
|
-
var diffs = this.diff_main(text1a, text2a, false, deadline);
|
|
232974
|
-
var diffsb = this.diff_main(text1b, text2b, false, deadline);
|
|
232975
|
-
|
|
232976
|
-
return diffs.concat(diffsb);
|
|
232977
|
-
};
|
|
232978
|
-
|
|
232979
|
-
|
|
232980
|
-
/**
|
|
232981
|
-
* Split two texts into an array of strings. Reduce the texts to a string of
|
|
232982
|
-
* hashes where each Unicode character represents one line.
|
|
232983
|
-
* @param {string} text1 First string.
|
|
232984
|
-
* @param {string} text2 Second string.
|
|
232985
|
-
* @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
|
|
232986
|
-
* An object containing the encoded text1, the encoded text2 and
|
|
232987
|
-
* the array of unique strings.
|
|
232988
|
-
* The zeroth element of the array of unique strings is intentionally blank.
|
|
232989
|
-
* @private
|
|
232990
|
-
*/
|
|
232991
|
-
diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
|
|
232992
|
-
var lineArray = []; // e.g. lineArray[4] == 'Hello\n'
|
|
232993
|
-
var lineHash = {}; // e.g. lineHash['Hello\n'] == 4
|
|
232994
|
-
|
|
232995
|
-
// '\x00' is a valid character, but various debuggers don't like it.
|
|
232996
|
-
// So we'll insert a junk entry to avoid generating a null character.
|
|
232997
|
-
lineArray[0] = '';
|
|
232998
|
-
|
|
232999
|
-
/**
|
|
233000
|
-
* Split a text into an array of strings. Reduce the texts to a string of
|
|
233001
|
-
* hashes where each Unicode character represents one line.
|
|
233002
|
-
* Modifies linearray and linehash through being a closure.
|
|
233003
|
-
* @param {string} text String to encode.
|
|
233004
|
-
* @return {string} Encoded string.
|
|
233005
|
-
* @private
|
|
233006
|
-
*/
|
|
233007
|
-
function diff_linesToCharsMunge_(text) {
|
|
233008
|
-
var chars = '';
|
|
233009
|
-
// Walk the text, pulling out a substring for each line.
|
|
233010
|
-
// text.split('\n') would would temporarily double our memory footprint.
|
|
233011
|
-
// Modifying text would create many large strings to garbage collect.
|
|
233012
|
-
var lineStart = 0;
|
|
233013
|
-
var lineEnd = -1;
|
|
233014
|
-
// Keeping our own length variable is faster than looking it up.
|
|
233015
|
-
var lineArrayLength = lineArray.length;
|
|
233016
|
-
while (lineEnd < text.length - 1) {
|
|
233017
|
-
lineEnd = text.indexOf('\n', lineStart);
|
|
233018
|
-
if (lineEnd == -1) {
|
|
233019
|
-
lineEnd = text.length - 1;
|
|
233020
|
-
}
|
|
233021
|
-
var line = text.substring(lineStart, lineEnd + 1);
|
|
233022
|
-
|
|
233023
|
-
if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
|
|
233024
|
-
(lineHash[line] !== undefined)) {
|
|
233025
|
-
chars += String.fromCharCode(lineHash[line]);
|
|
233026
|
-
} else {
|
|
233027
|
-
if (lineArrayLength == maxLines) {
|
|
233028
|
-
// Bail out at 65535 because
|
|
233029
|
-
// String.fromCharCode(65536) == String.fromCharCode(0)
|
|
233030
|
-
line = text.substring(lineStart);
|
|
233031
|
-
lineEnd = text.length;
|
|
233032
|
-
}
|
|
233033
|
-
chars += String.fromCharCode(lineArrayLength);
|
|
233034
|
-
lineHash[line] = lineArrayLength;
|
|
233035
|
-
lineArray[lineArrayLength++] = line;
|
|
233036
|
-
}
|
|
233037
|
-
lineStart = lineEnd + 1;
|
|
233038
|
-
}
|
|
233039
|
-
return chars;
|
|
233040
|
-
}
|
|
233041
|
-
// Allocate 2/3rds of the space for text1, the rest for text2.
|
|
233042
|
-
var maxLines = 40000;
|
|
233043
|
-
var chars1 = diff_linesToCharsMunge_(text1);
|
|
233044
|
-
maxLines = 65535;
|
|
233045
|
-
var chars2 = diff_linesToCharsMunge_(text2);
|
|
233046
|
-
return {chars1: chars1, chars2: chars2, lineArray: lineArray};
|
|
233047
|
-
};
|
|
233048
|
-
|
|
233049
|
-
|
|
233050
|
-
/**
|
|
233051
|
-
* Rehydrate the text in a diff from a string of line hashes to real lines of
|
|
233052
|
-
* text.
|
|
233053
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233054
|
-
* @param {!Array.<string>} lineArray Array of unique strings.
|
|
233055
|
-
* @private
|
|
233056
|
-
*/
|
|
233057
|
-
diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) {
|
|
233058
|
-
for (var i = 0; i < diffs.length; i++) {
|
|
233059
|
-
var chars = diffs[i][1];
|
|
233060
|
-
var text = [];
|
|
233061
|
-
for (var j = 0; j < chars.length; j++) {
|
|
233062
|
-
text[j] = lineArray[chars.charCodeAt(j)];
|
|
233063
|
-
}
|
|
233064
|
-
diffs[i][1] = text.join('');
|
|
233065
|
-
}
|
|
233066
|
-
};
|
|
233067
|
-
|
|
233068
|
-
|
|
233069
|
-
/**
|
|
233070
|
-
* Determine the common prefix of two strings.
|
|
233071
|
-
* @param {string} text1 First string.
|
|
233072
|
-
* @param {string} text2 Second string.
|
|
233073
|
-
* @return {number} The number of characters common to the start of each
|
|
233074
|
-
* string.
|
|
233075
|
-
*/
|
|
233076
|
-
diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) {
|
|
233077
|
-
// Quick check for common null cases.
|
|
233078
|
-
if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) {
|
|
233079
|
-
return 0;
|
|
233080
|
-
}
|
|
233081
|
-
// Binary search.
|
|
233082
|
-
// Performance analysis: https://neil.fraser.name/news/2007/10/09/
|
|
233083
|
-
var pointermin = 0;
|
|
233084
|
-
var pointermax = Math.min(text1.length, text2.length);
|
|
233085
|
-
var pointermid = pointermax;
|
|
233086
|
-
var pointerstart = 0;
|
|
233087
|
-
while (pointermin < pointermid) {
|
|
233088
|
-
if (text1.substring(pointerstart, pointermid) ==
|
|
233089
|
-
text2.substring(pointerstart, pointermid)) {
|
|
233090
|
-
pointermin = pointermid;
|
|
233091
|
-
pointerstart = pointermin;
|
|
233092
|
-
} else {
|
|
233093
|
-
pointermax = pointermid;
|
|
233094
|
-
}
|
|
233095
|
-
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|
233096
|
-
}
|
|
233097
|
-
return pointermid;
|
|
233098
|
-
};
|
|
233099
|
-
|
|
233100
|
-
|
|
233101
|
-
/**
|
|
233102
|
-
* Determine the common suffix of two strings.
|
|
233103
|
-
* @param {string} text1 First string.
|
|
233104
|
-
* @param {string} text2 Second string.
|
|
233105
|
-
* @return {number} The number of characters common to the end of each string.
|
|
233106
|
-
*/
|
|
233107
|
-
diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) {
|
|
233108
|
-
// Quick check for common null cases.
|
|
233109
|
-
if (!text1 || !text2 ||
|
|
233110
|
-
text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) {
|
|
233111
|
-
return 0;
|
|
233112
|
-
}
|
|
233113
|
-
// Binary search.
|
|
233114
|
-
// Performance analysis: https://neil.fraser.name/news/2007/10/09/
|
|
233115
|
-
var pointermin = 0;
|
|
233116
|
-
var pointermax = Math.min(text1.length, text2.length);
|
|
233117
|
-
var pointermid = pointermax;
|
|
233118
|
-
var pointerend = 0;
|
|
233119
|
-
while (pointermin < pointermid) {
|
|
233120
|
-
if (text1.substring(text1.length - pointermid, text1.length - pointerend) ==
|
|
233121
|
-
text2.substring(text2.length - pointermid, text2.length - pointerend)) {
|
|
233122
|
-
pointermin = pointermid;
|
|
233123
|
-
pointerend = pointermin;
|
|
233124
|
-
} else {
|
|
233125
|
-
pointermax = pointermid;
|
|
233126
|
-
}
|
|
233127
|
-
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|
233128
|
-
}
|
|
233129
|
-
return pointermid;
|
|
233130
|
-
};
|
|
233131
|
-
|
|
233132
|
-
|
|
233133
|
-
/**
|
|
233134
|
-
* Determine if the suffix of one string is the prefix of another.
|
|
233135
|
-
* @param {string} text1 First string.
|
|
233136
|
-
* @param {string} text2 Second string.
|
|
233137
|
-
* @return {number} The number of characters common to the end of the first
|
|
233138
|
-
* string and the start of the second string.
|
|
233139
|
-
* @private
|
|
233140
|
-
*/
|
|
233141
|
-
diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) {
|
|
233142
|
-
// Cache the text lengths to prevent multiple calls.
|
|
233143
|
-
var text1_length = text1.length;
|
|
233144
|
-
var text2_length = text2.length;
|
|
233145
|
-
// Eliminate the null case.
|
|
233146
|
-
if (text1_length == 0 || text2_length == 0) {
|
|
233147
|
-
return 0;
|
|
233148
|
-
}
|
|
233149
|
-
// Truncate the longer string.
|
|
233150
|
-
if (text1_length > text2_length) {
|
|
233151
|
-
text1 = text1.substring(text1_length - text2_length);
|
|
233152
|
-
} else if (text1_length < text2_length) {
|
|
233153
|
-
text2 = text2.substring(0, text1_length);
|
|
233154
|
-
}
|
|
233155
|
-
var text_length = Math.min(text1_length, text2_length);
|
|
233156
|
-
// Quick check for the worst case.
|
|
233157
|
-
if (text1 == text2) {
|
|
233158
|
-
return text_length;
|
|
233159
|
-
}
|
|
233160
|
-
|
|
233161
|
-
// Start by looking for a single character match
|
|
233162
|
-
// and increase length until no match is found.
|
|
233163
|
-
// Performance analysis: https://neil.fraser.name/news/2010/11/04/
|
|
233164
|
-
var best = 0;
|
|
233165
|
-
var length = 1;
|
|
233166
|
-
while (true) {
|
|
233167
|
-
var pattern = text1.substring(text_length - length);
|
|
233168
|
-
var found = text2.indexOf(pattern);
|
|
233169
|
-
if (found == -1) {
|
|
233170
|
-
return best;
|
|
233171
|
-
}
|
|
233172
|
-
length += found;
|
|
233173
|
-
if (found == 0 || text1.substring(text_length - length) ==
|
|
233174
|
-
text2.substring(0, length)) {
|
|
233175
|
-
best = length;
|
|
233176
|
-
length++;
|
|
233177
|
-
}
|
|
233178
|
-
}
|
|
233179
|
-
};
|
|
233180
|
-
|
|
233181
|
-
|
|
233182
|
-
/**
|
|
233183
|
-
* Do the two texts share a substring which is at least half the length of the
|
|
233184
|
-
* longer text?
|
|
233185
|
-
* This speedup can produce non-minimal diffs.
|
|
233186
|
-
* @param {string} text1 First string.
|
|
233187
|
-
* @param {string} text2 Second string.
|
|
233188
|
-
* @return {Array.<string>} Five element Array, containing the prefix of
|
|
233189
|
-
* text1, the suffix of text1, the prefix of text2, the suffix of
|
|
233190
|
-
* text2 and the common middle. Or null if there was no match.
|
|
233191
|
-
* @private
|
|
233192
|
-
*/
|
|
233193
|
-
diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) {
|
|
233194
|
-
if (this.Diff_Timeout <= 0) {
|
|
233195
|
-
// Don't risk returning a non-optimal diff if we have unlimited time.
|
|
233196
|
-
return null;
|
|
233197
|
-
}
|
|
233198
|
-
var longtext = text1.length > text2.length ? text1 : text2;
|
|
233199
|
-
var shorttext = text1.length > text2.length ? text2 : text1;
|
|
233200
|
-
if (longtext.length < 4 || shorttext.length * 2 < longtext.length) {
|
|
233201
|
-
return null; // Pointless.
|
|
233202
|
-
}
|
|
233203
|
-
var dmp = this; // 'this' becomes 'window' in a closure.
|
|
233204
|
-
|
|
233205
|
-
/**
|
|
233206
|
-
* Does a substring of shorttext exist within longtext such that the substring
|
|
233207
|
-
* is at least half the length of longtext?
|
|
233208
|
-
* Closure, but does not reference any external variables.
|
|
233209
|
-
* @param {string} longtext Longer string.
|
|
233210
|
-
* @param {string} shorttext Shorter string.
|
|
233211
|
-
* @param {number} i Start index of quarter length substring within longtext.
|
|
233212
|
-
* @return {Array.<string>} Five element Array, containing the prefix of
|
|
233213
|
-
* longtext, the suffix of longtext, the prefix of shorttext, the suffix
|
|
233214
|
-
* of shorttext and the common middle. Or null if there was no match.
|
|
233215
|
-
* @private
|
|
233216
|
-
*/
|
|
233217
|
-
function diff_halfMatchI_(longtext, shorttext, i) {
|
|
233218
|
-
// Start with a 1/4 length substring at position i as a seed.
|
|
233219
|
-
var seed = longtext.substring(i, i + Math.floor(longtext.length / 4));
|
|
233220
|
-
var j = -1;
|
|
233221
|
-
var best_common = '';
|
|
233222
|
-
var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b;
|
|
233223
|
-
while ((j = shorttext.indexOf(seed, j + 1)) != -1) {
|
|
233224
|
-
var prefixLength = dmp.diff_commonPrefix(longtext.substring(i),
|
|
233225
|
-
shorttext.substring(j));
|
|
233226
|
-
var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i),
|
|
233227
|
-
shorttext.substring(0, j));
|
|
233228
|
-
if (best_common.length < suffixLength + prefixLength) {
|
|
233229
|
-
best_common = shorttext.substring(j - suffixLength, j) +
|
|
233230
|
-
shorttext.substring(j, j + prefixLength);
|
|
233231
|
-
best_longtext_a = longtext.substring(0, i - suffixLength);
|
|
233232
|
-
best_longtext_b = longtext.substring(i + prefixLength);
|
|
233233
|
-
best_shorttext_a = shorttext.substring(0, j - suffixLength);
|
|
233234
|
-
best_shorttext_b = shorttext.substring(j + prefixLength);
|
|
233235
|
-
}
|
|
233236
|
-
}
|
|
233237
|
-
if (best_common.length * 2 >= longtext.length) {
|
|
233238
|
-
return [best_longtext_a, best_longtext_b,
|
|
233239
|
-
best_shorttext_a, best_shorttext_b, best_common];
|
|
233240
|
-
} else {
|
|
233241
|
-
return null;
|
|
233242
|
-
}
|
|
233243
|
-
}
|
|
233244
|
-
|
|
233245
|
-
// First check if the second quarter is the seed for a half-match.
|
|
233246
|
-
var hm1 = diff_halfMatchI_(longtext, shorttext,
|
|
233247
|
-
Math.ceil(longtext.length / 4));
|
|
233248
|
-
// Check again based on the third quarter.
|
|
233249
|
-
var hm2 = diff_halfMatchI_(longtext, shorttext,
|
|
233250
|
-
Math.ceil(longtext.length / 2));
|
|
233251
|
-
var hm;
|
|
233252
|
-
if (!hm1 && !hm2) {
|
|
233253
|
-
return null;
|
|
233254
|
-
} else if (!hm2) {
|
|
233255
|
-
hm = hm1;
|
|
233256
|
-
} else if (!hm1) {
|
|
233257
|
-
hm = hm2;
|
|
233258
|
-
} else {
|
|
233259
|
-
// Both matched. Select the longest.
|
|
233260
|
-
hm = hm1[4].length > hm2[4].length ? hm1 : hm2;
|
|
233261
|
-
}
|
|
233262
|
-
|
|
233263
|
-
// A half-match was found, sort out the return data.
|
|
233264
|
-
var text1_a, text1_b, text2_a, text2_b;
|
|
233265
|
-
if (text1.length > text2.length) {
|
|
233266
|
-
text1_a = hm[0];
|
|
233267
|
-
text1_b = hm[1];
|
|
233268
|
-
text2_a = hm[2];
|
|
233269
|
-
text2_b = hm[3];
|
|
233270
|
-
} else {
|
|
233271
|
-
text2_a = hm[0];
|
|
233272
|
-
text2_b = hm[1];
|
|
233273
|
-
text1_a = hm[2];
|
|
233274
|
-
text1_b = hm[3];
|
|
233275
|
-
}
|
|
233276
|
-
var mid_common = hm[4];
|
|
233277
|
-
return [text1_a, text1_b, text2_a, text2_b, mid_common];
|
|
233278
|
-
};
|
|
233279
|
-
|
|
233280
|
-
|
|
233281
|
-
/**
|
|
233282
|
-
* Reduce the number of edits by eliminating semantically trivial equalities.
|
|
233283
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233284
|
-
*/
|
|
233285
|
-
diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) {
|
|
233286
|
-
var changes = false;
|
|
233287
|
-
var equalities = []; // Stack of indices where equalities are found.
|
|
233288
|
-
var equalitiesLength = 0; // Keeping our own length var is faster in JS.
|
|
233289
|
-
/** @type {?string} */
|
|
233290
|
-
var lastEquality = null;
|
|
233291
|
-
// Always equal to diffs[equalities[equalitiesLength - 1]][1]
|
|
233292
|
-
var pointer = 0; // Index of current position.
|
|
233293
|
-
// Number of characters that changed prior to the equality.
|
|
233294
|
-
var length_insertions1 = 0;
|
|
233295
|
-
var length_deletions1 = 0;
|
|
233296
|
-
// Number of characters that changed after the equality.
|
|
233297
|
-
var length_insertions2 = 0;
|
|
233298
|
-
var length_deletions2 = 0;
|
|
233299
|
-
while (pointer < diffs.length) {
|
|
233300
|
-
if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
|
|
233301
|
-
equalities[equalitiesLength++] = pointer;
|
|
233302
|
-
length_insertions1 = length_insertions2;
|
|
233303
|
-
length_deletions1 = length_deletions2;
|
|
233304
|
-
length_insertions2 = 0;
|
|
233305
|
-
length_deletions2 = 0;
|
|
233306
|
-
lastEquality = diffs[pointer][1];
|
|
233307
|
-
} else { // An insertion or deletion.
|
|
233308
|
-
if (diffs[pointer][0] == DIFF_INSERT) {
|
|
233309
|
-
length_insertions2 += diffs[pointer][1].length;
|
|
233310
|
-
} else {
|
|
233311
|
-
length_deletions2 += diffs[pointer][1].length;
|
|
233312
|
-
}
|
|
233313
|
-
// Eliminate an equality that is smaller or equal to the edits on both
|
|
233314
|
-
// sides of it.
|
|
233315
|
-
if (lastEquality && (lastEquality.length <=
|
|
233316
|
-
Math.max(length_insertions1, length_deletions1)) &&
|
|
233317
|
-
(lastEquality.length <= Math.max(length_insertions2,
|
|
233318
|
-
length_deletions2))) {
|
|
233319
|
-
// Duplicate record.
|
|
233320
|
-
diffs.splice(equalities[equalitiesLength - 1], 0,
|
|
233321
|
-
new diff_match_patch.Diff(DIFF_DELETE, lastEquality));
|
|
233322
|
-
// Change second copy to insert.
|
|
233323
|
-
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
|
233324
|
-
// Throw away the equality we just deleted.
|
|
233325
|
-
equalitiesLength--;
|
|
233326
|
-
// Throw away the previous equality (it needs to be reevaluated).
|
|
233327
|
-
equalitiesLength--;
|
|
233328
|
-
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
|
|
233329
|
-
length_insertions1 = 0; // Reset the counters.
|
|
233330
|
-
length_deletions1 = 0;
|
|
233331
|
-
length_insertions2 = 0;
|
|
233332
|
-
length_deletions2 = 0;
|
|
233333
|
-
lastEquality = null;
|
|
233334
|
-
changes = true;
|
|
233335
|
-
}
|
|
233336
|
-
}
|
|
233337
|
-
pointer++;
|
|
233338
|
-
}
|
|
233339
|
-
|
|
233340
|
-
// Normalize the diff.
|
|
233341
|
-
if (changes) {
|
|
233342
|
-
this.diff_cleanupMerge(diffs);
|
|
233343
|
-
}
|
|
233344
|
-
this.diff_cleanupSemanticLossless(diffs);
|
|
233345
|
-
|
|
233346
|
-
// Find any overlaps between deletions and insertions.
|
|
233347
|
-
// e.g: <del>abcxxx</del><ins>xxxdef</ins>
|
|
233348
|
-
// -> <del>abc</del>xxx<ins>def</ins>
|
|
233349
|
-
// e.g: <del>xxxabc</del><ins>defxxx</ins>
|
|
233350
|
-
// -> <ins>def</ins>xxx<del>abc</del>
|
|
233351
|
-
// Only extract an overlap if it is as big as the edit ahead or behind it.
|
|
233352
|
-
pointer = 1;
|
|
233353
|
-
while (pointer < diffs.length) {
|
|
233354
|
-
if (diffs[pointer - 1][0] == DIFF_DELETE &&
|
|
233355
|
-
diffs[pointer][0] == DIFF_INSERT) {
|
|
233356
|
-
var deletion = diffs[pointer - 1][1];
|
|
233357
|
-
var insertion = diffs[pointer][1];
|
|
233358
|
-
var overlap_length1 = this.diff_commonOverlap_(deletion, insertion);
|
|
233359
|
-
var overlap_length2 = this.diff_commonOverlap_(insertion, deletion);
|
|
233360
|
-
if (overlap_length1 >= overlap_length2) {
|
|
233361
|
-
if (overlap_length1 >= deletion.length / 2 ||
|
|
233362
|
-
overlap_length1 >= insertion.length / 2) {
|
|
233363
|
-
// Overlap found. Insert an equality and trim the surrounding edits.
|
|
233364
|
-
diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL,
|
|
233365
|
-
insertion.substring(0, overlap_length1)));
|
|
233366
|
-
diffs[pointer - 1][1] =
|
|
233367
|
-
deletion.substring(0, deletion.length - overlap_length1);
|
|
233368
|
-
diffs[pointer + 1][1] = insertion.substring(overlap_length1);
|
|
233369
|
-
pointer++;
|
|
233370
|
-
}
|
|
233371
|
-
} else {
|
|
233372
|
-
if (overlap_length2 >= deletion.length / 2 ||
|
|
233373
|
-
overlap_length2 >= insertion.length / 2) {
|
|
233374
|
-
// Reverse overlap found.
|
|
233375
|
-
// Insert an equality and swap and trim the surrounding edits.
|
|
233376
|
-
diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL,
|
|
233377
|
-
deletion.substring(0, overlap_length2)));
|
|
233378
|
-
diffs[pointer - 1][0] = DIFF_INSERT;
|
|
233379
|
-
diffs[pointer - 1][1] =
|
|
233380
|
-
insertion.substring(0, insertion.length - overlap_length2);
|
|
233381
|
-
diffs[pointer + 1][0] = DIFF_DELETE;
|
|
233382
|
-
diffs[pointer + 1][1] =
|
|
233383
|
-
deletion.substring(overlap_length2);
|
|
233384
|
-
pointer++;
|
|
233385
|
-
}
|
|
233386
|
-
}
|
|
233387
|
-
pointer++;
|
|
233388
|
-
}
|
|
233389
|
-
pointer++;
|
|
233390
|
-
}
|
|
233391
|
-
};
|
|
233392
|
-
|
|
233393
|
-
|
|
233394
|
-
/**
|
|
233395
|
-
* Look for single edits surrounded on both sides by equalities
|
|
233396
|
-
* which can be shifted sideways to align the edit to a word boundary.
|
|
233397
|
-
* e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
|
|
233398
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233399
|
-
*/
|
|
233400
|
-
diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) {
|
|
233401
|
-
/**
|
|
233402
|
-
* Given two strings, compute a score representing whether the internal
|
|
233403
|
-
* boundary falls on logical boundaries.
|
|
233404
|
-
* Scores range from 6 (best) to 0 (worst).
|
|
233405
|
-
* Closure, but does not reference any external variables.
|
|
233406
|
-
* @param {string} one First string.
|
|
233407
|
-
* @param {string} two Second string.
|
|
233408
|
-
* @return {number} The score.
|
|
233409
|
-
* @private
|
|
233410
|
-
*/
|
|
233411
|
-
function diff_cleanupSemanticScore_(one, two) {
|
|
233412
|
-
if (!one || !two) {
|
|
233413
|
-
// Edges are the best.
|
|
233414
|
-
return 6;
|
|
233415
|
-
}
|
|
233416
|
-
|
|
233417
|
-
// Each port of this function behaves slightly differently due to
|
|
233418
|
-
// subtle differences in each language's definition of things like
|
|
233419
|
-
// 'whitespace'. Since this function's purpose is largely cosmetic,
|
|
233420
|
-
// the choice has been made to use each language's native features
|
|
233421
|
-
// rather than force total conformity.
|
|
233422
|
-
var char1 = one.charAt(one.length - 1);
|
|
233423
|
-
var char2 = two.charAt(0);
|
|
233424
|
-
var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_);
|
|
233425
|
-
var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_);
|
|
233426
|
-
var whitespace1 = nonAlphaNumeric1 &&
|
|
233427
|
-
char1.match(diff_match_patch.whitespaceRegex_);
|
|
233428
|
-
var whitespace2 = nonAlphaNumeric2 &&
|
|
233429
|
-
char2.match(diff_match_patch.whitespaceRegex_);
|
|
233430
|
-
var lineBreak1 = whitespace1 &&
|
|
233431
|
-
char1.match(diff_match_patch.linebreakRegex_);
|
|
233432
|
-
var lineBreak2 = whitespace2 &&
|
|
233433
|
-
char2.match(diff_match_patch.linebreakRegex_);
|
|
233434
|
-
var blankLine1 = lineBreak1 &&
|
|
233435
|
-
one.match(diff_match_patch.blanklineEndRegex_);
|
|
233436
|
-
var blankLine2 = lineBreak2 &&
|
|
233437
|
-
two.match(diff_match_patch.blanklineStartRegex_);
|
|
233438
|
-
|
|
233439
|
-
if (blankLine1 || blankLine2) {
|
|
233440
|
-
// Five points for blank lines.
|
|
233441
|
-
return 5;
|
|
233442
|
-
} else if (lineBreak1 || lineBreak2) {
|
|
233443
|
-
// Four points for line breaks.
|
|
233444
|
-
return 4;
|
|
233445
|
-
} else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
|
|
233446
|
-
// Three points for end of sentences.
|
|
233447
|
-
return 3;
|
|
233448
|
-
} else if (whitespace1 || whitespace2) {
|
|
233449
|
-
// Two points for whitespace.
|
|
233450
|
-
return 2;
|
|
233451
|
-
} else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
|
|
233452
|
-
// One point for non-alphanumeric.
|
|
233453
|
-
return 1;
|
|
233454
|
-
}
|
|
233455
|
-
return 0;
|
|
233456
|
-
}
|
|
233457
|
-
|
|
233458
|
-
var pointer = 1;
|
|
233459
|
-
// Intentionally ignore the first and last element (don't need checking).
|
|
233460
|
-
while (pointer < diffs.length - 1) {
|
|
233461
|
-
if (diffs[pointer - 1][0] == DIFF_EQUAL &&
|
|
233462
|
-
diffs[pointer + 1][0] == DIFF_EQUAL) {
|
|
233463
|
-
// This is a single edit surrounded by equalities.
|
|
233464
|
-
var equality1 = diffs[pointer - 1][1];
|
|
233465
|
-
var edit = diffs[pointer][1];
|
|
233466
|
-
var equality2 = diffs[pointer + 1][1];
|
|
233467
|
-
|
|
233468
|
-
// First, shift the edit as far left as possible.
|
|
233469
|
-
var commonOffset = this.diff_commonSuffix(equality1, edit);
|
|
233470
|
-
if (commonOffset) {
|
|
233471
|
-
var commonString = edit.substring(edit.length - commonOffset);
|
|
233472
|
-
equality1 = equality1.substring(0, equality1.length - commonOffset);
|
|
233473
|
-
edit = commonString + edit.substring(0, edit.length - commonOffset);
|
|
233474
|
-
equality2 = commonString + equality2;
|
|
233475
|
-
}
|
|
233476
|
-
|
|
233477
|
-
// Second, step character by character right, looking for the best fit.
|
|
233478
|
-
var bestEquality1 = equality1;
|
|
233479
|
-
var bestEdit = edit;
|
|
233480
|
-
var bestEquality2 = equality2;
|
|
233481
|
-
var bestScore = diff_cleanupSemanticScore_(equality1, edit) +
|
|
233482
|
-
diff_cleanupSemanticScore_(edit, equality2);
|
|
233483
|
-
while (edit.charAt(0) === equality2.charAt(0)) {
|
|
233484
|
-
equality1 += edit.charAt(0);
|
|
233485
|
-
edit = edit.substring(1) + equality2.charAt(0);
|
|
233486
|
-
equality2 = equality2.substring(1);
|
|
233487
|
-
var score = diff_cleanupSemanticScore_(equality1, edit) +
|
|
233488
|
-
diff_cleanupSemanticScore_(edit, equality2);
|
|
233489
|
-
// The >= encourages trailing rather than leading whitespace on edits.
|
|
233490
|
-
if (score >= bestScore) {
|
|
233491
|
-
bestScore = score;
|
|
233492
|
-
bestEquality1 = equality1;
|
|
233493
|
-
bestEdit = edit;
|
|
233494
|
-
bestEquality2 = equality2;
|
|
233495
|
-
}
|
|
233496
|
-
}
|
|
233497
|
-
|
|
233498
|
-
if (diffs[pointer - 1][1] != bestEquality1) {
|
|
233499
|
-
// We have an improvement, save it back to the diff.
|
|
233500
|
-
if (bestEquality1) {
|
|
233501
|
-
diffs[pointer - 1][1] = bestEquality1;
|
|
233502
|
-
} else {
|
|
233503
|
-
diffs.splice(pointer - 1, 1);
|
|
233504
|
-
pointer--;
|
|
233505
|
-
}
|
|
233506
|
-
diffs[pointer][1] = bestEdit;
|
|
233507
|
-
if (bestEquality2) {
|
|
233508
|
-
diffs[pointer + 1][1] = bestEquality2;
|
|
233509
|
-
} else {
|
|
233510
|
-
diffs.splice(pointer + 1, 1);
|
|
233511
|
-
pointer--;
|
|
233512
|
-
}
|
|
233513
|
-
}
|
|
233514
|
-
}
|
|
233515
|
-
pointer++;
|
|
233516
|
-
}
|
|
233517
|
-
};
|
|
233518
|
-
|
|
233519
|
-
// Define some regex patterns for matching boundaries.
|
|
233520
|
-
diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/;
|
|
233521
|
-
diff_match_patch.whitespaceRegex_ = /\s/;
|
|
233522
|
-
diff_match_patch.linebreakRegex_ = /[\r\n]/;
|
|
233523
|
-
diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/;
|
|
233524
|
-
diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/;
|
|
233525
|
-
|
|
233526
|
-
/**
|
|
233527
|
-
* Reduce the number of edits by eliminating operationally trivial equalities.
|
|
233528
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233529
|
-
*/
|
|
233530
|
-
diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) {
|
|
233531
|
-
var changes = false;
|
|
233532
|
-
var equalities = []; // Stack of indices where equalities are found.
|
|
233533
|
-
var equalitiesLength = 0; // Keeping our own length var is faster in JS.
|
|
233534
|
-
/** @type {?string} */
|
|
233535
|
-
var lastEquality = null;
|
|
233536
|
-
// Always equal to diffs[equalities[equalitiesLength - 1]][1]
|
|
233537
|
-
var pointer = 0; // Index of current position.
|
|
233538
|
-
// Is there an insertion operation before the last equality.
|
|
233539
|
-
var pre_ins = false;
|
|
233540
|
-
// Is there a deletion operation before the last equality.
|
|
233541
|
-
var pre_del = false;
|
|
233542
|
-
// Is there an insertion operation after the last equality.
|
|
233543
|
-
var post_ins = false;
|
|
233544
|
-
// Is there a deletion operation after the last equality.
|
|
233545
|
-
var post_del = false;
|
|
233546
|
-
while (pointer < diffs.length) {
|
|
233547
|
-
if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
|
|
233548
|
-
if (diffs[pointer][1].length < this.Diff_EditCost &&
|
|
233549
|
-
(post_ins || post_del)) {
|
|
233550
|
-
// Candidate found.
|
|
233551
|
-
equalities[equalitiesLength++] = pointer;
|
|
233552
|
-
pre_ins = post_ins;
|
|
233553
|
-
pre_del = post_del;
|
|
233554
|
-
lastEquality = diffs[pointer][1];
|
|
233555
|
-
} else {
|
|
233556
|
-
// Not a candidate, and can never become one.
|
|
233557
|
-
equalitiesLength = 0;
|
|
233558
|
-
lastEquality = null;
|
|
233559
|
-
}
|
|
233560
|
-
post_ins = post_del = false;
|
|
233561
|
-
} else { // An insertion or deletion.
|
|
233562
|
-
if (diffs[pointer][0] == DIFF_DELETE) {
|
|
233563
|
-
post_del = true;
|
|
233564
|
-
} else {
|
|
233565
|
-
post_ins = true;
|
|
233566
|
-
}
|
|
233567
|
-
/*
|
|
233568
|
-
* Five types to be split:
|
|
233569
|
-
* <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
|
|
233570
|
-
* <ins>A</ins>X<ins>C</ins><del>D</del>
|
|
233571
|
-
* <ins>A</ins><del>B</del>X<ins>C</ins>
|
|
233572
|
-
* <ins>A</del>X<ins>C</ins><del>D</del>
|
|
233573
|
-
* <ins>A</ins><del>B</del>X<del>C</del>
|
|
233574
|
-
*/
|
|
233575
|
-
if (lastEquality && ((pre_ins && pre_del && post_ins && post_del) ||
|
|
233576
|
-
((lastEquality.length < this.Diff_EditCost / 2) &&
|
|
233577
|
-
(pre_ins + pre_del + post_ins + post_del) == 3))) {
|
|
233578
|
-
// Duplicate record.
|
|
233579
|
-
diffs.splice(equalities[equalitiesLength - 1], 0,
|
|
233580
|
-
new diff_match_patch.Diff(DIFF_DELETE, lastEquality));
|
|
233581
|
-
// Change second copy to insert.
|
|
233582
|
-
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
|
233583
|
-
equalitiesLength--; // Throw away the equality we just deleted;
|
|
233584
|
-
lastEquality = null;
|
|
233585
|
-
if (pre_ins && pre_del) {
|
|
233586
|
-
// No changes made which could affect previous entry, keep going.
|
|
233587
|
-
post_ins = post_del = true;
|
|
233588
|
-
equalitiesLength = 0;
|
|
233589
|
-
} else {
|
|
233590
|
-
equalitiesLength--; // Throw away the previous equality.
|
|
233591
|
-
pointer = equalitiesLength > 0 ?
|
|
233592
|
-
equalities[equalitiesLength - 1] : -1;
|
|
233593
|
-
post_ins = post_del = false;
|
|
233594
|
-
}
|
|
233595
|
-
changes = true;
|
|
233596
|
-
}
|
|
233597
|
-
}
|
|
233598
|
-
pointer++;
|
|
233599
|
-
}
|
|
233600
|
-
|
|
233601
|
-
if (changes) {
|
|
233602
|
-
this.diff_cleanupMerge(diffs);
|
|
233603
|
-
}
|
|
233604
|
-
};
|
|
233605
|
-
|
|
233606
|
-
|
|
233607
|
-
/**
|
|
233608
|
-
* Reorder and merge like edit sections. Merge equalities.
|
|
233609
|
-
* Any edit section can move as long as it doesn't cross an equality.
|
|
233610
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233611
|
-
*/
|
|
233612
|
-
diff_match_patch.prototype.diff_cleanupMerge = function(diffs) {
|
|
233613
|
-
// Add a dummy entry at the end.
|
|
233614
|
-
diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, ''));
|
|
233615
|
-
var pointer = 0;
|
|
233616
|
-
var count_delete = 0;
|
|
233617
|
-
var count_insert = 0;
|
|
233618
|
-
var text_delete = '';
|
|
233619
|
-
var text_insert = '';
|
|
233620
|
-
var commonlength;
|
|
233621
|
-
while (pointer < diffs.length) {
|
|
233622
|
-
switch (diffs[pointer][0]) {
|
|
233623
|
-
case DIFF_INSERT:
|
|
233624
|
-
count_insert++;
|
|
233625
|
-
text_insert += diffs[pointer][1];
|
|
233626
|
-
pointer++;
|
|
233627
|
-
break;
|
|
233628
|
-
case DIFF_DELETE:
|
|
233629
|
-
count_delete++;
|
|
233630
|
-
text_delete += diffs[pointer][1];
|
|
233631
|
-
pointer++;
|
|
233632
|
-
break;
|
|
233633
|
-
case DIFF_EQUAL:
|
|
233634
|
-
// Upon reaching an equality, check for prior redundancies.
|
|
233635
|
-
if (count_delete + count_insert > 1) {
|
|
233636
|
-
if (count_delete !== 0 && count_insert !== 0) {
|
|
233637
|
-
// Factor out any common prefixies.
|
|
233638
|
-
commonlength = this.diff_commonPrefix(text_insert, text_delete);
|
|
233639
|
-
if (commonlength !== 0) {
|
|
233640
|
-
if ((pointer - count_delete - count_insert) > 0 &&
|
|
233641
|
-
diffs[pointer - count_delete - count_insert - 1][0] ==
|
|
233642
|
-
DIFF_EQUAL) {
|
|
233643
|
-
diffs[pointer - count_delete - count_insert - 1][1] +=
|
|
233644
|
-
text_insert.substring(0, commonlength);
|
|
233645
|
-
} else {
|
|
233646
|
-
diffs.splice(0, 0, new diff_match_patch.Diff(DIFF_EQUAL,
|
|
233647
|
-
text_insert.substring(0, commonlength)));
|
|
233648
|
-
pointer++;
|
|
233649
|
-
}
|
|
233650
|
-
text_insert = text_insert.substring(commonlength);
|
|
233651
|
-
text_delete = text_delete.substring(commonlength);
|
|
233652
|
-
}
|
|
233653
|
-
// Factor out any common suffixies.
|
|
233654
|
-
commonlength = this.diff_commonSuffix(text_insert, text_delete);
|
|
233655
|
-
if (commonlength !== 0) {
|
|
233656
|
-
diffs[pointer][1] = text_insert.substring(text_insert.length -
|
|
233657
|
-
commonlength) + diffs[pointer][1];
|
|
233658
|
-
text_insert = text_insert.substring(0, text_insert.length -
|
|
233659
|
-
commonlength);
|
|
233660
|
-
text_delete = text_delete.substring(0, text_delete.length -
|
|
233661
|
-
commonlength);
|
|
233662
|
-
}
|
|
233663
|
-
}
|
|
233664
|
-
// Delete the offending records and add the merged ones.
|
|
233665
|
-
pointer -= count_delete + count_insert;
|
|
233666
|
-
diffs.splice(pointer, count_delete + count_insert);
|
|
233667
|
-
if (text_delete.length) {
|
|
233668
|
-
diffs.splice(pointer, 0,
|
|
233669
|
-
new diff_match_patch.Diff(DIFF_DELETE, text_delete));
|
|
233670
|
-
pointer++;
|
|
233671
|
-
}
|
|
233672
|
-
if (text_insert.length) {
|
|
233673
|
-
diffs.splice(pointer, 0,
|
|
233674
|
-
new diff_match_patch.Diff(DIFF_INSERT, text_insert));
|
|
233675
|
-
pointer++;
|
|
233676
|
-
}
|
|
233677
|
-
pointer++;
|
|
233678
|
-
} else if (pointer !== 0 && diffs[pointer - 1][0] == DIFF_EQUAL) {
|
|
233679
|
-
// Merge this equality with the previous one.
|
|
233680
|
-
diffs[pointer - 1][1] += diffs[pointer][1];
|
|
233681
|
-
diffs.splice(pointer, 1);
|
|
233682
|
-
} else {
|
|
233683
|
-
pointer++;
|
|
233684
|
-
}
|
|
233685
|
-
count_insert = 0;
|
|
233686
|
-
count_delete = 0;
|
|
233687
|
-
text_delete = '';
|
|
233688
|
-
text_insert = '';
|
|
233689
|
-
break;
|
|
233690
|
-
}
|
|
233691
|
-
}
|
|
233692
|
-
if (diffs[diffs.length - 1][1] === '') {
|
|
233693
|
-
diffs.pop(); // Remove the dummy entry at the end.
|
|
233694
|
-
}
|
|
233695
|
-
|
|
233696
|
-
// Second pass: look for single edits surrounded on both sides by equalities
|
|
233697
|
-
// which can be shifted sideways to eliminate an equality.
|
|
233698
|
-
// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
|
|
233699
|
-
var changes = false;
|
|
233700
|
-
pointer = 1;
|
|
233701
|
-
// Intentionally ignore the first and last element (don't need checking).
|
|
233702
|
-
while (pointer < diffs.length - 1) {
|
|
233703
|
-
if (diffs[pointer - 1][0] == DIFF_EQUAL &&
|
|
233704
|
-
diffs[pointer + 1][0] == DIFF_EQUAL) {
|
|
233705
|
-
// This is a single edit surrounded by equalities.
|
|
233706
|
-
if (diffs[pointer][1].substring(diffs[pointer][1].length -
|
|
233707
|
-
diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) {
|
|
233708
|
-
// Shift the edit over the previous equality.
|
|
233709
|
-
diffs[pointer][1] = diffs[pointer - 1][1] +
|
|
233710
|
-
diffs[pointer][1].substring(0, diffs[pointer][1].length -
|
|
233711
|
-
diffs[pointer - 1][1].length);
|
|
233712
|
-
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
|
|
233713
|
-
diffs.splice(pointer - 1, 1);
|
|
233714
|
-
changes = true;
|
|
233715
|
-
} else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ==
|
|
233716
|
-
diffs[pointer + 1][1]) {
|
|
233717
|
-
// Shift the edit over the next equality.
|
|
233718
|
-
diffs[pointer - 1][1] += diffs[pointer + 1][1];
|
|
233719
|
-
diffs[pointer][1] =
|
|
233720
|
-
diffs[pointer][1].substring(diffs[pointer + 1][1].length) +
|
|
233721
|
-
diffs[pointer + 1][1];
|
|
233722
|
-
diffs.splice(pointer + 1, 1);
|
|
233723
|
-
changes = true;
|
|
233724
|
-
}
|
|
233725
|
-
}
|
|
233726
|
-
pointer++;
|
|
233727
|
-
}
|
|
233728
|
-
// If shifts were made, the diff needs reordering and another shift sweep.
|
|
233729
|
-
if (changes) {
|
|
233730
|
-
this.diff_cleanupMerge(diffs);
|
|
233731
|
-
}
|
|
233732
|
-
};
|
|
233733
|
-
|
|
233734
|
-
|
|
233735
|
-
/**
|
|
233736
|
-
* loc is a location in text1, compute and return the equivalent location in
|
|
233737
|
-
* text2.
|
|
233738
|
-
* e.g. 'The cat' vs 'The big cat', 1->1, 5->8
|
|
233739
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233740
|
-
* @param {number} loc Location within text1.
|
|
233741
|
-
* @return {number} Location within text2.
|
|
233742
|
-
*/
|
|
233743
|
-
diff_match_patch.prototype.diff_xIndex = function(diffs, loc) {
|
|
233744
|
-
var chars1 = 0;
|
|
233745
|
-
var chars2 = 0;
|
|
233746
|
-
var last_chars1 = 0;
|
|
233747
|
-
var last_chars2 = 0;
|
|
233748
|
-
var x;
|
|
233749
|
-
for (x = 0; x < diffs.length; x++) {
|
|
233750
|
-
if (diffs[x][0] !== DIFF_INSERT) { // Equality or deletion.
|
|
233751
|
-
chars1 += diffs[x][1].length;
|
|
233752
|
-
}
|
|
233753
|
-
if (diffs[x][0] !== DIFF_DELETE) { // Equality or insertion.
|
|
233754
|
-
chars2 += diffs[x][1].length;
|
|
233755
|
-
}
|
|
233756
|
-
if (chars1 > loc) { // Overshot the location.
|
|
233757
|
-
break;
|
|
233758
|
-
}
|
|
233759
|
-
last_chars1 = chars1;
|
|
233760
|
-
last_chars2 = chars2;
|
|
233761
|
-
}
|
|
233762
|
-
// Was the location was deleted?
|
|
233763
|
-
if (diffs.length != x && diffs[x][0] === DIFF_DELETE) {
|
|
233764
|
-
return last_chars2;
|
|
233765
|
-
}
|
|
233766
|
-
// Add the remaining character length.
|
|
233767
|
-
return last_chars2 + (loc - last_chars1);
|
|
233768
|
-
};
|
|
233769
|
-
|
|
233770
|
-
|
|
233771
|
-
/**
|
|
233772
|
-
* Convert a diff array into a pretty HTML report.
|
|
233773
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233774
|
-
* @return {string} HTML representation.
|
|
233775
|
-
*/
|
|
233776
|
-
diff_match_patch.prototype.diff_prettyHtml = function(diffs) {
|
|
233777
|
-
var html = [];
|
|
233778
|
-
var pattern_amp = /&/g;
|
|
233779
|
-
var pattern_lt = /</g;
|
|
233780
|
-
var pattern_gt = />/g;
|
|
233781
|
-
var pattern_para = /\n/g;
|
|
233782
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
233783
|
-
var op = diffs[x][0]; // Operation (insert, delete, equal)
|
|
233784
|
-
var data = diffs[x][1]; // Text of change.
|
|
233785
|
-
var text = data.replace(pattern_amp, '&').replace(pattern_lt, '<')
|
|
233786
|
-
.replace(pattern_gt, '>').replace(pattern_para, '¶<br>');
|
|
233787
|
-
switch (op) {
|
|
233788
|
-
case DIFF_INSERT:
|
|
233789
|
-
html[x] = '<ins style="background:#e6ffe6;">' + text + '</ins>';
|
|
233790
|
-
break;
|
|
233791
|
-
case DIFF_DELETE:
|
|
233792
|
-
html[x] = '<del style="background:#ffe6e6;">' + text + '</del>';
|
|
233793
|
-
break;
|
|
233794
|
-
case DIFF_EQUAL:
|
|
233795
|
-
html[x] = '<span>' + text + '</span>';
|
|
233796
|
-
break;
|
|
233797
|
-
}
|
|
233798
|
-
}
|
|
233799
|
-
return html.join('');
|
|
233800
|
-
};
|
|
233801
|
-
|
|
233802
|
-
|
|
233803
|
-
/**
|
|
233804
|
-
* Compute and return the source text (all equalities and deletions).
|
|
233805
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233806
|
-
* @return {string} Source text.
|
|
233807
|
-
*/
|
|
233808
|
-
diff_match_patch.prototype.diff_text1 = function(diffs) {
|
|
233809
|
-
var text = [];
|
|
233810
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
233811
|
-
if (diffs[x][0] !== DIFF_INSERT) {
|
|
233812
|
-
text[x] = diffs[x][1];
|
|
233813
|
-
}
|
|
233814
|
-
}
|
|
233815
|
-
return text.join('');
|
|
233816
|
-
};
|
|
233817
|
-
|
|
233818
|
-
|
|
233819
|
-
/**
|
|
233820
|
-
* Compute and return the destination text (all equalities and insertions).
|
|
233821
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233822
|
-
* @return {string} Destination text.
|
|
233823
|
-
*/
|
|
233824
|
-
diff_match_patch.prototype.diff_text2 = function(diffs) {
|
|
233825
|
-
var text = [];
|
|
233826
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
233827
|
-
if (diffs[x][0] !== DIFF_DELETE) {
|
|
233828
|
-
text[x] = diffs[x][1];
|
|
233829
|
-
}
|
|
233830
|
-
}
|
|
233831
|
-
return text.join('');
|
|
233832
|
-
};
|
|
233833
|
-
|
|
233834
|
-
|
|
233835
|
-
/**
|
|
233836
|
-
* Compute the Levenshtein distance; the number of inserted, deleted or
|
|
233837
|
-
* substituted characters.
|
|
233838
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233839
|
-
* @return {number} Number of changes.
|
|
233840
|
-
*/
|
|
233841
|
-
diff_match_patch.prototype.diff_levenshtein = function(diffs) {
|
|
233842
|
-
var levenshtein = 0;
|
|
233843
|
-
var insertions = 0;
|
|
233844
|
-
var deletions = 0;
|
|
233845
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
233846
|
-
var op = diffs[x][0];
|
|
233847
|
-
var data = diffs[x][1];
|
|
233848
|
-
switch (op) {
|
|
233849
|
-
case DIFF_INSERT:
|
|
233850
|
-
insertions += data.length;
|
|
233851
|
-
break;
|
|
233852
|
-
case DIFF_DELETE:
|
|
233853
|
-
deletions += data.length;
|
|
233854
|
-
break;
|
|
233855
|
-
case DIFF_EQUAL:
|
|
233856
|
-
// A deletion and an insertion is one substitution.
|
|
233857
|
-
levenshtein += Math.max(insertions, deletions);
|
|
233858
|
-
insertions = 0;
|
|
233859
|
-
deletions = 0;
|
|
233860
|
-
break;
|
|
233861
|
-
}
|
|
233862
|
-
}
|
|
233863
|
-
levenshtein += Math.max(insertions, deletions);
|
|
233864
|
-
return levenshtein;
|
|
233865
|
-
};
|
|
233866
|
-
|
|
233867
|
-
|
|
233868
|
-
/**
|
|
233869
|
-
* Crush the diff into an encoded string which describes the operations
|
|
233870
|
-
* required to transform text1 into text2.
|
|
233871
|
-
* E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'.
|
|
233872
|
-
* Operations are tab-separated. Inserted text is escaped using %xx notation.
|
|
233873
|
-
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
233874
|
-
* @return {string} Delta text.
|
|
233875
|
-
*/
|
|
233876
|
-
diff_match_patch.prototype.diff_toDelta = function(diffs) {
|
|
233877
|
-
var text = [];
|
|
233878
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
233879
|
-
switch (diffs[x][0]) {
|
|
233880
|
-
case DIFF_INSERT:
|
|
233881
|
-
text[x] = '+' + encodeURI(diffs[x][1]);
|
|
233882
|
-
break;
|
|
233883
|
-
case DIFF_DELETE:
|
|
233884
|
-
text[x] = '-' + diffs[x][1].length;
|
|
233885
|
-
break;
|
|
233886
|
-
case DIFF_EQUAL:
|
|
233887
|
-
text[x] = '=' + diffs[x][1].length;
|
|
233888
|
-
break;
|
|
233889
|
-
}
|
|
233890
|
-
}
|
|
233891
|
-
return text.join('\t').replace(/%20/g, ' ');
|
|
233892
|
-
};
|
|
233893
|
-
|
|
233894
|
-
|
|
233895
|
-
/**
|
|
233896
|
-
* Given the original text1, and an encoded string which describes the
|
|
233897
|
-
* operations required to transform text1 into text2, compute the full diff.
|
|
233898
|
-
* @param {string} text1 Source string for the diff.
|
|
233899
|
-
* @param {string} delta Delta text.
|
|
233900
|
-
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|
233901
|
-
* @throws {!Error} If invalid input.
|
|
233902
|
-
*/
|
|
233903
|
-
diff_match_patch.prototype.diff_fromDelta = function(text1, delta) {
|
|
233904
|
-
var diffs = [];
|
|
233905
|
-
var diffsLength = 0; // Keeping our own length var is faster in JS.
|
|
233906
|
-
var pointer = 0; // Cursor in text1
|
|
233907
|
-
var tokens = delta.split(/\t/g);
|
|
233908
|
-
for (var x = 0; x < tokens.length; x++) {
|
|
233909
|
-
// Each token begins with a one character parameter which specifies the
|
|
233910
|
-
// operation of this token (delete, insert, equality).
|
|
233911
|
-
var param = tokens[x].substring(1);
|
|
233912
|
-
switch (tokens[x].charAt(0)) {
|
|
233913
|
-
case '+':
|
|
233914
|
-
try {
|
|
233915
|
-
diffs[diffsLength++] =
|
|
233916
|
-
new diff_match_patch.Diff(DIFF_INSERT, decodeURI(param));
|
|
233917
|
-
} catch (ex) {
|
|
233918
|
-
// Malformed URI sequence.
|
|
233919
|
-
throw new Error('Illegal escape in diff_fromDelta: ' + param);
|
|
233920
|
-
}
|
|
233921
|
-
break;
|
|
233922
|
-
case '-':
|
|
233923
|
-
// Fall through.
|
|
233924
|
-
case '=':
|
|
233925
|
-
var n = parseInt(param, 10);
|
|
233926
|
-
if (isNaN(n) || n < 0) {
|
|
233927
|
-
throw new Error('Invalid number in diff_fromDelta: ' + param);
|
|
233928
|
-
}
|
|
233929
|
-
var text = text1.substring(pointer, pointer += n);
|
|
233930
|
-
if (tokens[x].charAt(0) == '=') {
|
|
233931
|
-
diffs[diffsLength++] = new diff_match_patch.Diff(DIFF_EQUAL, text);
|
|
233932
|
-
} else {
|
|
233933
|
-
diffs[diffsLength++] = new diff_match_patch.Diff(DIFF_DELETE, text);
|
|
233934
|
-
}
|
|
233935
|
-
break;
|
|
233936
|
-
default:
|
|
233937
|
-
// Blank tokens are ok (from a trailing \t).
|
|
233938
|
-
// Anything else is an error.
|
|
233939
|
-
if (tokens[x]) {
|
|
233940
|
-
throw new Error('Invalid diff operation in diff_fromDelta: ' +
|
|
233941
|
-
tokens[x]);
|
|
233942
|
-
}
|
|
233943
|
-
}
|
|
233944
|
-
}
|
|
233945
|
-
if (pointer != text1.length) {
|
|
233946
|
-
throw new Error('Delta length (' + pointer +
|
|
233947
|
-
') does not equal source text length (' + text1.length + ').');
|
|
233948
|
-
}
|
|
233949
|
-
return diffs;
|
|
233950
|
-
};
|
|
233951
|
-
|
|
233952
|
-
|
|
233953
|
-
// MATCH FUNCTIONS
|
|
233954
|
-
|
|
233955
|
-
|
|
233956
|
-
/**
|
|
233957
|
-
* Locate the best instance of 'pattern' in 'text' near 'loc'.
|
|
233958
|
-
* @param {string} text The text to search.
|
|
233959
|
-
* @param {string} pattern The pattern to search for.
|
|
233960
|
-
* @param {number} loc The location to search around.
|
|
233961
|
-
* @return {number} Best match index or -1.
|
|
233962
|
-
*/
|
|
233963
|
-
diff_match_patch.prototype.match_main = function(text, pattern, loc) {
|
|
233964
|
-
// Check for null inputs.
|
|
233965
|
-
if (text == null || pattern == null || loc == null) {
|
|
233966
|
-
throw new Error('Null input. (match_main)');
|
|
233967
|
-
}
|
|
233968
|
-
|
|
233969
|
-
loc = Math.max(0, Math.min(loc, text.length));
|
|
233970
|
-
if (text == pattern) {
|
|
233971
|
-
// Shortcut (potentially not guaranteed by the algorithm)
|
|
233972
|
-
return 0;
|
|
233973
|
-
} else if (!text.length) {
|
|
233974
|
-
// Nothing to match.
|
|
233975
|
-
return -1;
|
|
233976
|
-
} else if (text.substring(loc, loc + pattern.length) == pattern) {
|
|
233977
|
-
// Perfect match at the perfect spot! (Includes case of null pattern)
|
|
233978
|
-
return loc;
|
|
233979
|
-
} else {
|
|
233980
|
-
// Do a fuzzy compare.
|
|
233981
|
-
return this.match_bitap_(text, pattern, loc);
|
|
233982
|
-
}
|
|
233983
|
-
};
|
|
233984
|
-
|
|
233985
|
-
|
|
233986
|
-
/**
|
|
233987
|
-
* Locate the best instance of 'pattern' in 'text' near 'loc' using the
|
|
233988
|
-
* Bitap algorithm.
|
|
233989
|
-
* @param {string} text The text to search.
|
|
233990
|
-
* @param {string} pattern The pattern to search for.
|
|
233991
|
-
* @param {number} loc The location to search around.
|
|
233992
|
-
* @return {number} Best match index or -1.
|
|
233993
|
-
* @private
|
|
233994
|
-
*/
|
|
233995
|
-
diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) {
|
|
233996
|
-
if (pattern.length > this.Match_MaxBits) {
|
|
233997
|
-
throw new Error('Pattern too long for this browser.');
|
|
233998
|
-
}
|
|
233999
|
-
|
|
234000
|
-
// Initialise the alphabet.
|
|
234001
|
-
var s = this.match_alphabet_(pattern);
|
|
234002
|
-
|
|
234003
|
-
var dmp = this; // 'this' becomes 'window' in a closure.
|
|
234004
|
-
|
|
234005
|
-
/**
|
|
234006
|
-
* Compute and return the score for a match with e errors and x location.
|
|
234007
|
-
* Accesses loc and pattern through being a closure.
|
|
234008
|
-
* @param {number} e Number of errors in match.
|
|
234009
|
-
* @param {number} x Location of match.
|
|
234010
|
-
* @return {number} Overall score for match (0.0 = good, 1.0 = bad).
|
|
234011
|
-
* @private
|
|
234012
|
-
*/
|
|
234013
|
-
function match_bitapScore_(e, x) {
|
|
234014
|
-
var accuracy = e / pattern.length;
|
|
234015
|
-
var proximity = Math.abs(loc - x);
|
|
234016
|
-
if (!dmp.Match_Distance) {
|
|
234017
|
-
// Dodge divide by zero error.
|
|
234018
|
-
return proximity ? 1.0 : accuracy;
|
|
234019
|
-
}
|
|
234020
|
-
return accuracy + (proximity / dmp.Match_Distance);
|
|
234021
|
-
}
|
|
234022
|
-
|
|
234023
|
-
// Highest score beyond which we give up.
|
|
234024
|
-
var score_threshold = this.Match_Threshold;
|
|
234025
|
-
// Is there a nearby exact match? (speedup)
|
|
234026
|
-
var best_loc = text.indexOf(pattern, loc);
|
|
234027
|
-
if (best_loc != -1) {
|
|
234028
|
-
score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold);
|
|
234029
|
-
// What about in the other direction? (speedup)
|
|
234030
|
-
best_loc = text.lastIndexOf(pattern, loc + pattern.length);
|
|
234031
|
-
if (best_loc != -1) {
|
|
234032
|
-
score_threshold =
|
|
234033
|
-
Math.min(match_bitapScore_(0, best_loc), score_threshold);
|
|
234034
|
-
}
|
|
234035
|
-
}
|
|
234036
|
-
|
|
234037
|
-
// Initialise the bit arrays.
|
|
234038
|
-
var matchmask = 1 << (pattern.length - 1);
|
|
234039
|
-
best_loc = -1;
|
|
234040
|
-
|
|
234041
|
-
var bin_min, bin_mid;
|
|
234042
|
-
var bin_max = pattern.length + text.length;
|
|
234043
|
-
var last_rd;
|
|
234044
|
-
for (var d = 0; d < pattern.length; d++) {
|
|
234045
|
-
// Scan for the best match; each iteration allows for one more error.
|
|
234046
|
-
// Run a binary search to determine how far from 'loc' we can stray at this
|
|
234047
|
-
// error level.
|
|
234048
|
-
bin_min = 0;
|
|
234049
|
-
bin_mid = bin_max;
|
|
234050
|
-
while (bin_min < bin_mid) {
|
|
234051
|
-
if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) {
|
|
234052
|
-
bin_min = bin_mid;
|
|
234053
|
-
} else {
|
|
234054
|
-
bin_max = bin_mid;
|
|
234055
|
-
}
|
|
234056
|
-
bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min);
|
|
234057
|
-
}
|
|
234058
|
-
// Use the result from this iteration as the maximum for the next.
|
|
234059
|
-
bin_max = bin_mid;
|
|
234060
|
-
var start = Math.max(1, loc - bin_mid + 1);
|
|
234061
|
-
var finish = Math.min(loc + bin_mid, text.length) + pattern.length;
|
|
234062
|
-
|
|
234063
|
-
var rd = Array(finish + 2);
|
|
234064
|
-
rd[finish + 1] = (1 << d) - 1;
|
|
234065
|
-
for (var j = finish; j >= start; j--) {
|
|
234066
|
-
// The alphabet (s) is a sparse hash, so the following line generates
|
|
234067
|
-
// warnings.
|
|
234068
|
-
var charMatch = s[text.charAt(j - 1)];
|
|
234069
|
-
if (d === 0) { // First pass: exact match.
|
|
234070
|
-
rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
|
|
234071
|
-
} else { // Subsequent passes: fuzzy match.
|
|
234072
|
-
rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) |
|
|
234073
|
-
(((last_rd[j + 1] | last_rd[j]) << 1) | 1) |
|
|
234074
|
-
last_rd[j + 1];
|
|
234075
|
-
}
|
|
234076
|
-
if (rd[j] & matchmask) {
|
|
234077
|
-
var score = match_bitapScore_(d, j - 1);
|
|
234078
|
-
// This match will almost certainly be better than any existing match.
|
|
234079
|
-
// But check anyway.
|
|
234080
|
-
if (score <= score_threshold) {
|
|
234081
|
-
// Told you so.
|
|
234082
|
-
score_threshold = score;
|
|
234083
|
-
best_loc = j - 1;
|
|
234084
|
-
if (best_loc > loc) {
|
|
234085
|
-
// When passing loc, don't exceed our current distance from loc.
|
|
234086
|
-
start = Math.max(1, 2 * loc - best_loc);
|
|
234087
|
-
} else {
|
|
234088
|
-
// Already passed loc, downhill from here on in.
|
|
234089
|
-
break;
|
|
234090
|
-
}
|
|
234091
|
-
}
|
|
234092
|
-
}
|
|
234093
|
-
}
|
|
234094
|
-
// No hope for a (better) match at greater error levels.
|
|
234095
|
-
if (match_bitapScore_(d + 1, loc) > score_threshold) {
|
|
234096
|
-
break;
|
|
234097
|
-
}
|
|
234098
|
-
last_rd = rd;
|
|
234099
|
-
}
|
|
234100
|
-
return best_loc;
|
|
234101
|
-
};
|
|
234102
|
-
|
|
234103
|
-
|
|
234104
|
-
/**
|
|
234105
|
-
* Initialise the alphabet for the Bitap algorithm.
|
|
234106
|
-
* @param {string} pattern The text to encode.
|
|
234107
|
-
* @return {!Object} Hash of character locations.
|
|
234108
|
-
* @private
|
|
234109
|
-
*/
|
|
234110
|
-
diff_match_patch.prototype.match_alphabet_ = function(pattern) {
|
|
234111
|
-
var s = {};
|
|
234112
|
-
for (var i = 0; i < pattern.length; i++) {
|
|
234113
|
-
s[pattern.charAt(i)] = 0;
|
|
234114
|
-
}
|
|
234115
|
-
for (var i = 0; i < pattern.length; i++) {
|
|
234116
|
-
s[pattern.charAt(i)] |= 1 << (pattern.length - i - 1);
|
|
234117
|
-
}
|
|
234118
|
-
return s;
|
|
234119
|
-
};
|
|
234120
|
-
|
|
234121
|
-
|
|
234122
|
-
// PATCH FUNCTIONS
|
|
234123
|
-
|
|
234124
|
-
|
|
234125
|
-
/**
|
|
234126
|
-
* Increase the context until it is unique,
|
|
234127
|
-
* but don't let the pattern expand beyond Match_MaxBits.
|
|
234128
|
-
* @param {!diff_match_patch.patch_obj} patch The patch to grow.
|
|
234129
|
-
* @param {string} text Source text.
|
|
234130
|
-
* @private
|
|
234131
|
-
*/
|
|
234132
|
-
diff_match_patch.prototype.patch_addContext_ = function(patch, text) {
|
|
234133
|
-
if (text.length == 0) {
|
|
234134
|
-
return;
|
|
234135
|
-
}
|
|
234136
|
-
if (patch.start2 === null) {
|
|
234137
|
-
throw Error('patch not initialized');
|
|
234138
|
-
}
|
|
234139
|
-
var pattern = text.substring(patch.start2, patch.start2 + patch.length1);
|
|
234140
|
-
var padding = 0;
|
|
234141
|
-
|
|
234142
|
-
// Look for the first and last matches of pattern in text. If two different
|
|
234143
|
-
// matches are found, increase the pattern length.
|
|
234144
|
-
while (text.indexOf(pattern) != text.lastIndexOf(pattern) &&
|
|
234145
|
-
pattern.length < this.Match_MaxBits - this.Patch_Margin -
|
|
234146
|
-
this.Patch_Margin) {
|
|
234147
|
-
padding += this.Patch_Margin;
|
|
234148
|
-
pattern = text.substring(patch.start2 - padding,
|
|
234149
|
-
patch.start2 + patch.length1 + padding);
|
|
234150
|
-
}
|
|
234151
|
-
// Add one chunk for good luck.
|
|
234152
|
-
padding += this.Patch_Margin;
|
|
234153
|
-
|
|
234154
|
-
// Add the prefix.
|
|
234155
|
-
var prefix = text.substring(patch.start2 - padding, patch.start2);
|
|
234156
|
-
if (prefix) {
|
|
234157
|
-
patch.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, prefix));
|
|
234158
|
-
}
|
|
234159
|
-
// Add the suffix.
|
|
234160
|
-
var suffix = text.substring(patch.start2 + patch.length1,
|
|
234161
|
-
patch.start2 + patch.length1 + padding);
|
|
234162
|
-
if (suffix) {
|
|
234163
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, suffix));
|
|
234164
|
-
}
|
|
234165
|
-
|
|
234166
|
-
// Roll back the start points.
|
|
234167
|
-
patch.start1 -= prefix.length;
|
|
234168
|
-
patch.start2 -= prefix.length;
|
|
234169
|
-
// Extend the lengths.
|
|
234170
|
-
patch.length1 += prefix.length + suffix.length;
|
|
234171
|
-
patch.length2 += prefix.length + suffix.length;
|
|
234172
|
-
};
|
|
234173
|
-
|
|
234174
|
-
|
|
234175
|
-
/**
|
|
234176
|
-
* Compute a list of patches to turn text1 into text2.
|
|
234177
|
-
* Use diffs if provided, otherwise compute it ourselves.
|
|
234178
|
-
* There are four ways to call this function, depending on what data is
|
|
234179
|
-
* available to the caller:
|
|
234180
|
-
* Method 1:
|
|
234181
|
-
* a = text1, b = text2
|
|
234182
|
-
* Method 2:
|
|
234183
|
-
* a = diffs
|
|
234184
|
-
* Method 3 (optimal):
|
|
234185
|
-
* a = text1, b = diffs
|
|
234186
|
-
* Method 4 (deprecated, use method 3):
|
|
234187
|
-
* a = text1, b = text2, c = diffs
|
|
234188
|
-
*
|
|
234189
|
-
* @param {string|!Array.<!diff_match_patch.Diff>} a text1 (methods 1,3,4) or
|
|
234190
|
-
* Array of diff tuples for text1 to text2 (method 2).
|
|
234191
|
-
* @param {string|!Array.<!diff_match_patch.Diff>=} opt_b text2 (methods 1,4) or
|
|
234192
|
-
* Array of diff tuples for text1 to text2 (method 3) or undefined (method 2).
|
|
234193
|
-
* @param {string|!Array.<!diff_match_patch.Diff>=} opt_c Array of diff tuples
|
|
234194
|
-
* for text1 to text2 (method 4) or undefined (methods 1,2,3).
|
|
234195
|
-
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|
234196
|
-
*/
|
|
234197
|
-
diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) {
|
|
234198
|
-
var text1, diffs;
|
|
234199
|
-
if (typeof a == 'string' && typeof opt_b == 'string' &&
|
|
234200
|
-
typeof opt_c == 'undefined') {
|
|
234201
|
-
// Method 1: text1, text2
|
|
234202
|
-
// Compute diffs from text1 and text2.
|
|
234203
|
-
text1 = /** @type {string} */(a);
|
|
234204
|
-
diffs = this.diff_main(text1, /** @type {string} */(opt_b), true);
|
|
234205
|
-
if (diffs.length > 2) {
|
|
234206
|
-
this.diff_cleanupSemantic(diffs);
|
|
234207
|
-
this.diff_cleanupEfficiency(diffs);
|
|
234208
|
-
}
|
|
234209
|
-
} else if (a && typeof a == 'object' && typeof opt_b == 'undefined' &&
|
|
234210
|
-
typeof opt_c == 'undefined') {
|
|
234211
|
-
// Method 2: diffs
|
|
234212
|
-
// Compute text1 from diffs.
|
|
234213
|
-
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(a);
|
|
234214
|
-
text1 = this.diff_text1(diffs);
|
|
234215
|
-
} else if (typeof a == 'string' && opt_b && typeof opt_b == 'object' &&
|
|
234216
|
-
typeof opt_c == 'undefined') {
|
|
234217
|
-
// Method 3: text1, diffs
|
|
234218
|
-
text1 = /** @type {string} */(a);
|
|
234219
|
-
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_b);
|
|
234220
|
-
} else if (typeof a == 'string' && typeof opt_b == 'string' &&
|
|
234221
|
-
opt_c && typeof opt_c == 'object') {
|
|
234222
|
-
// Method 4: text1, text2, diffs
|
|
234223
|
-
// text2 is not used.
|
|
234224
|
-
text1 = /** @type {string} */(a);
|
|
234225
|
-
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_c);
|
|
234226
|
-
} else {
|
|
234227
|
-
throw new Error('Unknown call format to patch_make.');
|
|
234228
|
-
}
|
|
234229
|
-
|
|
234230
|
-
if (diffs.length === 0) {
|
|
234231
|
-
return []; // Get rid of the null case.
|
|
234232
|
-
}
|
|
234233
|
-
var patches = [];
|
|
234234
|
-
var patch = new diff_match_patch.patch_obj();
|
|
234235
|
-
var patchDiffLength = 0; // Keeping our own length var is faster in JS.
|
|
234236
|
-
var char_count1 = 0; // Number of characters into the text1 string.
|
|
234237
|
-
var char_count2 = 0; // Number of characters into the text2 string.
|
|
234238
|
-
// Start with text1 (prepatch_text) and apply the diffs until we arrive at
|
|
234239
|
-
// text2 (postpatch_text). We recreate the patches one by one to determine
|
|
234240
|
-
// context info.
|
|
234241
|
-
var prepatch_text = text1;
|
|
234242
|
-
var postpatch_text = text1;
|
|
234243
|
-
for (var x = 0; x < diffs.length; x++) {
|
|
234244
|
-
var diff_type = diffs[x][0];
|
|
234245
|
-
var diff_text = diffs[x][1];
|
|
234246
|
-
|
|
234247
|
-
if (!patchDiffLength && diff_type !== DIFF_EQUAL) {
|
|
234248
|
-
// A new patch starts here.
|
|
234249
|
-
patch.start1 = char_count1;
|
|
234250
|
-
patch.start2 = char_count2;
|
|
234251
|
-
}
|
|
234252
|
-
|
|
234253
|
-
switch (diff_type) {
|
|
234254
|
-
case DIFF_INSERT:
|
|
234255
|
-
patch.diffs[patchDiffLength++] = diffs[x];
|
|
234256
|
-
patch.length2 += diff_text.length;
|
|
234257
|
-
postpatch_text = postpatch_text.substring(0, char_count2) + diff_text +
|
|
234258
|
-
postpatch_text.substring(char_count2);
|
|
234259
|
-
break;
|
|
234260
|
-
case DIFF_DELETE:
|
|
234261
|
-
patch.length1 += diff_text.length;
|
|
234262
|
-
patch.diffs[patchDiffLength++] = diffs[x];
|
|
234263
|
-
postpatch_text = postpatch_text.substring(0, char_count2) +
|
|
234264
|
-
postpatch_text.substring(char_count2 +
|
|
234265
|
-
diff_text.length);
|
|
234266
|
-
break;
|
|
234267
|
-
case DIFF_EQUAL:
|
|
234268
|
-
if (diff_text.length <= 2 * this.Patch_Margin &&
|
|
234269
|
-
patchDiffLength && diffs.length != x + 1) {
|
|
234270
|
-
// Small equality inside a patch.
|
|
234271
|
-
patch.diffs[patchDiffLength++] = diffs[x];
|
|
234272
|
-
patch.length1 += diff_text.length;
|
|
234273
|
-
patch.length2 += diff_text.length;
|
|
234274
|
-
} else if (diff_text.length >= 2 * this.Patch_Margin) {
|
|
234275
|
-
// Time for a new patch.
|
|
234276
|
-
if (patchDiffLength) {
|
|
234277
|
-
this.patch_addContext_(patch, prepatch_text);
|
|
234278
|
-
patches.push(patch);
|
|
234279
|
-
patch = new diff_match_patch.patch_obj();
|
|
234280
|
-
patchDiffLength = 0;
|
|
234281
|
-
// Unlike Unidiff, our patch lists have a rolling context.
|
|
234282
|
-
// https://github.com/google/diff-match-patch/wiki/Unidiff
|
|
234283
|
-
// Update prepatch text & pos to reflect the application of the
|
|
234284
|
-
// just completed patch.
|
|
234285
|
-
prepatch_text = postpatch_text;
|
|
234286
|
-
char_count1 = char_count2;
|
|
234287
|
-
}
|
|
234288
|
-
}
|
|
234289
|
-
break;
|
|
234290
|
-
}
|
|
234291
|
-
|
|
234292
|
-
// Update the current character count.
|
|
234293
|
-
if (diff_type !== DIFF_INSERT) {
|
|
234294
|
-
char_count1 += diff_text.length;
|
|
234295
|
-
}
|
|
234296
|
-
if (diff_type !== DIFF_DELETE) {
|
|
234297
|
-
char_count2 += diff_text.length;
|
|
234298
|
-
}
|
|
234299
|
-
}
|
|
234300
|
-
// Pick up the leftover patch if not empty.
|
|
234301
|
-
if (patchDiffLength) {
|
|
234302
|
-
this.patch_addContext_(patch, prepatch_text);
|
|
234303
|
-
patches.push(patch);
|
|
234304
|
-
}
|
|
234305
|
-
|
|
234306
|
-
return patches;
|
|
234307
|
-
};
|
|
234308
|
-
|
|
234309
|
-
|
|
234310
|
-
/**
|
|
234311
|
-
* Given an array of patches, return another array that is identical.
|
|
234312
|
-
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|
234313
|
-
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|
234314
|
-
*/
|
|
234315
|
-
diff_match_patch.prototype.patch_deepCopy = function(patches) {
|
|
234316
|
-
// Making deep copies is hard in JavaScript.
|
|
234317
|
-
var patchesCopy = [];
|
|
234318
|
-
for (var x = 0; x < patches.length; x++) {
|
|
234319
|
-
var patch = patches[x];
|
|
234320
|
-
var patchCopy = new diff_match_patch.patch_obj();
|
|
234321
|
-
patchCopy.diffs = [];
|
|
234322
|
-
for (var y = 0; y < patch.diffs.length; y++) {
|
|
234323
|
-
patchCopy.diffs[y] =
|
|
234324
|
-
new diff_match_patch.Diff(patch.diffs[y][0], patch.diffs[y][1]);
|
|
234325
|
-
}
|
|
234326
|
-
patchCopy.start1 = patch.start1;
|
|
234327
|
-
patchCopy.start2 = patch.start2;
|
|
234328
|
-
patchCopy.length1 = patch.length1;
|
|
234329
|
-
patchCopy.length2 = patch.length2;
|
|
234330
|
-
patchesCopy[x] = patchCopy;
|
|
234331
|
-
}
|
|
234332
|
-
return patchesCopy;
|
|
234333
|
-
};
|
|
234334
|
-
|
|
234335
|
-
|
|
234336
|
-
/**
|
|
234337
|
-
* Merge a set of patches onto the text. Return a patched text, as well
|
|
234338
|
-
* as a list of true/false values indicating which patches were applied.
|
|
234339
|
-
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|
234340
|
-
* @param {string} text Old text.
|
|
234341
|
-
* @return {!Array.<string|!Array.<boolean>>} Two element Array, containing the
|
|
234342
|
-
* new text and an array of boolean values.
|
|
234343
|
-
*/
|
|
234344
|
-
diff_match_patch.prototype.patch_apply = function(patches, text) {
|
|
234345
|
-
if (patches.length == 0) {
|
|
234346
|
-
return [text, []];
|
|
234347
|
-
}
|
|
234348
|
-
|
|
234349
|
-
// Deep copy the patches so that no changes are made to originals.
|
|
234350
|
-
patches = this.patch_deepCopy(patches);
|
|
234351
|
-
|
|
234352
|
-
var nullPadding = this.patch_addPadding(patches);
|
|
234353
|
-
text = nullPadding + text + nullPadding;
|
|
234354
|
-
|
|
234355
|
-
this.patch_splitMax(patches);
|
|
234356
|
-
// delta keeps track of the offset between the expected and actual location
|
|
234357
|
-
// of the previous patch. If there are patches expected at positions 10 and
|
|
234358
|
-
// 20, but the first patch was found at 12, delta is 2 and the second patch
|
|
234359
|
-
// has an effective expected position of 22.
|
|
234360
|
-
var delta = 0;
|
|
234361
|
-
var results = [];
|
|
234362
|
-
for (var x = 0; x < patches.length; x++) {
|
|
234363
|
-
var expected_loc = patches[x].start2 + delta;
|
|
234364
|
-
var text1 = this.diff_text1(patches[x].diffs);
|
|
234365
|
-
var start_loc;
|
|
234366
|
-
var end_loc = -1;
|
|
234367
|
-
if (text1.length > this.Match_MaxBits) {
|
|
234368
|
-
// patch_splitMax will only provide an oversized pattern in the case of
|
|
234369
|
-
// a monster delete.
|
|
234370
|
-
start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits),
|
|
234371
|
-
expected_loc);
|
|
234372
|
-
if (start_loc != -1) {
|
|
234373
|
-
end_loc = this.match_main(text,
|
|
234374
|
-
text1.substring(text1.length - this.Match_MaxBits),
|
|
234375
|
-
expected_loc + text1.length - this.Match_MaxBits);
|
|
234376
|
-
if (end_loc == -1 || start_loc >= end_loc) {
|
|
234377
|
-
// Can't find valid trailing context. Drop this patch.
|
|
234378
|
-
start_loc = -1;
|
|
234379
|
-
}
|
|
234380
|
-
}
|
|
234381
|
-
} else {
|
|
234382
|
-
start_loc = this.match_main(text, text1, expected_loc);
|
|
234383
|
-
}
|
|
234384
|
-
if (start_loc == -1) {
|
|
234385
|
-
// No match found. :(
|
|
234386
|
-
results[x] = false;
|
|
234387
|
-
// Subtract the delta for this failed patch from subsequent patches.
|
|
234388
|
-
delta -= patches[x].length2 - patches[x].length1;
|
|
234389
|
-
} else {
|
|
234390
|
-
// Found a match. :)
|
|
234391
|
-
results[x] = true;
|
|
234392
|
-
delta = start_loc - expected_loc;
|
|
234393
|
-
var text2;
|
|
234394
|
-
if (end_loc == -1) {
|
|
234395
|
-
text2 = text.substring(start_loc, start_loc + text1.length);
|
|
234396
|
-
} else {
|
|
234397
|
-
text2 = text.substring(start_loc, end_loc + this.Match_MaxBits);
|
|
234398
|
-
}
|
|
234399
|
-
if (text1 == text2) {
|
|
234400
|
-
// Perfect match, just shove the replacement text in.
|
|
234401
|
-
text = text.substring(0, start_loc) +
|
|
234402
|
-
this.diff_text2(patches[x].diffs) +
|
|
234403
|
-
text.substring(start_loc + text1.length);
|
|
234404
|
-
} else {
|
|
234405
|
-
// Imperfect match. Run a diff to get a framework of equivalent
|
|
234406
|
-
// indices.
|
|
234407
|
-
var diffs = this.diff_main(text1, text2, false);
|
|
234408
|
-
if (text1.length > this.Match_MaxBits &&
|
|
234409
|
-
this.diff_levenshtein(diffs) / text1.length >
|
|
234410
|
-
this.Patch_DeleteThreshold) {
|
|
234411
|
-
// The end points match, but the content is unacceptably bad.
|
|
234412
|
-
results[x] = false;
|
|
234413
|
-
} else {
|
|
234414
|
-
this.diff_cleanupSemanticLossless(diffs);
|
|
234415
|
-
var index1 = 0;
|
|
234416
|
-
var index2;
|
|
234417
|
-
for (var y = 0; y < patches[x].diffs.length; y++) {
|
|
234418
|
-
var mod = patches[x].diffs[y];
|
|
234419
|
-
if (mod[0] !== DIFF_EQUAL) {
|
|
234420
|
-
index2 = this.diff_xIndex(diffs, index1);
|
|
234421
|
-
}
|
|
234422
|
-
if (mod[0] === DIFF_INSERT) { // Insertion
|
|
234423
|
-
text = text.substring(0, start_loc + index2) + mod[1] +
|
|
234424
|
-
text.substring(start_loc + index2);
|
|
234425
|
-
} else if (mod[0] === DIFF_DELETE) { // Deletion
|
|
234426
|
-
text = text.substring(0, start_loc + index2) +
|
|
234427
|
-
text.substring(start_loc + this.diff_xIndex(diffs,
|
|
234428
|
-
index1 + mod[1].length));
|
|
234429
|
-
}
|
|
234430
|
-
if (mod[0] !== DIFF_DELETE) {
|
|
234431
|
-
index1 += mod[1].length;
|
|
234432
|
-
}
|
|
234433
|
-
}
|
|
234434
|
-
}
|
|
234435
|
-
}
|
|
234436
|
-
}
|
|
234437
|
-
}
|
|
234438
|
-
// Strip the padding off.
|
|
234439
|
-
text = text.substring(nullPadding.length, text.length - nullPadding.length);
|
|
234440
|
-
return [text, results];
|
|
234441
|
-
};
|
|
234442
|
-
|
|
234443
|
-
|
|
234444
|
-
/**
|
|
234445
|
-
* Add some padding on text start and end so that edges can match something.
|
|
234446
|
-
* Intended to be called only from within patch_apply.
|
|
234447
|
-
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|
234448
|
-
* @return {string} The padding string added to each side.
|
|
234449
|
-
*/
|
|
234450
|
-
diff_match_patch.prototype.patch_addPadding = function(patches) {
|
|
234451
|
-
var paddingLength = this.Patch_Margin;
|
|
234452
|
-
var nullPadding = '';
|
|
234453
|
-
for (var x = 1; x <= paddingLength; x++) {
|
|
234454
|
-
nullPadding += String.fromCharCode(x);
|
|
234455
|
-
}
|
|
234456
|
-
|
|
234457
|
-
// Bump all the patches forward.
|
|
234458
|
-
for (var x = 0; x < patches.length; x++) {
|
|
234459
|
-
patches[x].start1 += paddingLength;
|
|
234460
|
-
patches[x].start2 += paddingLength;
|
|
234461
|
-
}
|
|
234462
|
-
|
|
234463
|
-
// Add some padding on start of first diff.
|
|
234464
|
-
var patch = patches[0];
|
|
234465
|
-
var diffs = patch.diffs;
|
|
234466
|
-
if (diffs.length == 0 || diffs[0][0] != DIFF_EQUAL) {
|
|
234467
|
-
// Add nullPadding equality.
|
|
234468
|
-
diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, nullPadding));
|
|
234469
|
-
patch.start1 -= paddingLength; // Should be 0.
|
|
234470
|
-
patch.start2 -= paddingLength; // Should be 0.
|
|
234471
|
-
patch.length1 += paddingLength;
|
|
234472
|
-
patch.length2 += paddingLength;
|
|
234473
|
-
} else if (paddingLength > diffs[0][1].length) {
|
|
234474
|
-
// Grow first equality.
|
|
234475
|
-
var extraLength = paddingLength - diffs[0][1].length;
|
|
234476
|
-
diffs[0][1] = nullPadding.substring(diffs[0][1].length) + diffs[0][1];
|
|
234477
|
-
patch.start1 -= extraLength;
|
|
234478
|
-
patch.start2 -= extraLength;
|
|
234479
|
-
patch.length1 += extraLength;
|
|
234480
|
-
patch.length2 += extraLength;
|
|
234481
|
-
}
|
|
234482
|
-
|
|
234483
|
-
// Add some padding on end of last diff.
|
|
234484
|
-
patch = patches[patches.length - 1];
|
|
234485
|
-
diffs = patch.diffs;
|
|
234486
|
-
if (diffs.length == 0 || diffs[diffs.length - 1][0] != DIFF_EQUAL) {
|
|
234487
|
-
// Add nullPadding equality.
|
|
234488
|
-
diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, nullPadding));
|
|
234489
|
-
patch.length1 += paddingLength;
|
|
234490
|
-
patch.length2 += paddingLength;
|
|
234491
|
-
} else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
234492
|
-
// Grow last equality.
|
|
234493
|
-
var extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
234494
|
-
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength);
|
|
234495
|
-
patch.length1 += extraLength;
|
|
234496
|
-
patch.length2 += extraLength;
|
|
234497
|
-
}
|
|
234498
|
-
|
|
234499
|
-
return nullPadding;
|
|
234500
|
-
};
|
|
234501
|
-
|
|
234502
|
-
|
|
234503
|
-
/**
|
|
234504
|
-
* Look through the patches and break up any which are longer than the maximum
|
|
234505
|
-
* limit of the match algorithm.
|
|
234506
|
-
* Intended to be called only from within patch_apply.
|
|
234507
|
-
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|
234508
|
-
*/
|
|
234509
|
-
diff_match_patch.prototype.patch_splitMax = function(patches) {
|
|
234510
|
-
var patch_size = this.Match_MaxBits;
|
|
234511
|
-
for (var x = 0; x < patches.length; x++) {
|
|
234512
|
-
if (patches[x].length1 <= patch_size) {
|
|
234513
|
-
continue;
|
|
234514
|
-
}
|
|
234515
|
-
var bigpatch = patches[x];
|
|
234516
|
-
// Remove the big old patch.
|
|
234517
|
-
patches.splice(x--, 1);
|
|
234518
|
-
var start1 = bigpatch.start1;
|
|
234519
|
-
var start2 = bigpatch.start2;
|
|
234520
|
-
var precontext = '';
|
|
234521
|
-
while (bigpatch.diffs.length !== 0) {
|
|
234522
|
-
// Create one of several smaller patches.
|
|
234523
|
-
var patch = new diff_match_patch.patch_obj();
|
|
234524
|
-
var empty = true;
|
|
234525
|
-
patch.start1 = start1 - precontext.length;
|
|
234526
|
-
patch.start2 = start2 - precontext.length;
|
|
234527
|
-
if (precontext !== '') {
|
|
234528
|
-
patch.length1 = patch.length2 = precontext.length;
|
|
234529
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, precontext));
|
|
234530
|
-
}
|
|
234531
|
-
while (bigpatch.diffs.length !== 0 &&
|
|
234532
|
-
patch.length1 < patch_size - this.Patch_Margin) {
|
|
234533
|
-
var diff_type = bigpatch.diffs[0][0];
|
|
234534
|
-
var diff_text = bigpatch.diffs[0][1];
|
|
234535
|
-
if (diff_type === DIFF_INSERT) {
|
|
234536
|
-
// Insertions are harmless.
|
|
234537
|
-
patch.length2 += diff_text.length;
|
|
234538
|
-
start2 += diff_text.length;
|
|
234539
|
-
patch.diffs.push(bigpatch.diffs.shift());
|
|
234540
|
-
empty = false;
|
|
234541
|
-
} else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 &&
|
|
234542
|
-
patch.diffs[0][0] == DIFF_EQUAL &&
|
|
234543
|
-
diff_text.length > 2 * patch_size) {
|
|
234544
|
-
// This is a large deletion. Let it pass in one chunk.
|
|
234545
|
-
patch.length1 += diff_text.length;
|
|
234546
|
-
start1 += diff_text.length;
|
|
234547
|
-
empty = false;
|
|
234548
|
-
patch.diffs.push(new diff_match_patch.Diff(diff_type, diff_text));
|
|
234549
|
-
bigpatch.diffs.shift();
|
|
234550
|
-
} else {
|
|
234551
|
-
// Deletion or equality. Only take as much as we can stomach.
|
|
234552
|
-
diff_text = diff_text.substring(0,
|
|
234553
|
-
patch_size - patch.length1 - this.Patch_Margin);
|
|
234554
|
-
patch.length1 += diff_text.length;
|
|
234555
|
-
start1 += diff_text.length;
|
|
234556
|
-
if (diff_type === DIFF_EQUAL) {
|
|
234557
|
-
patch.length2 += diff_text.length;
|
|
234558
|
-
start2 += diff_text.length;
|
|
234559
|
-
} else {
|
|
234560
|
-
empty = false;
|
|
234561
|
-
}
|
|
234562
|
-
patch.diffs.push(new diff_match_patch.Diff(diff_type, diff_text));
|
|
234563
|
-
if (diff_text == bigpatch.diffs[0][1]) {
|
|
234564
|
-
bigpatch.diffs.shift();
|
|
234565
|
-
} else {
|
|
234566
|
-
bigpatch.diffs[0][1] =
|
|
234567
|
-
bigpatch.diffs[0][1].substring(diff_text.length);
|
|
234568
|
-
}
|
|
234569
|
-
}
|
|
234570
|
-
}
|
|
234571
|
-
// Compute the head context for the next patch.
|
|
234572
|
-
precontext = this.diff_text2(patch.diffs);
|
|
234573
|
-
precontext =
|
|
234574
|
-
precontext.substring(precontext.length - this.Patch_Margin);
|
|
234575
|
-
// Append the end context for this patch.
|
|
234576
|
-
var postcontext = this.diff_text1(bigpatch.diffs)
|
|
234577
|
-
.substring(0, this.Patch_Margin);
|
|
234578
|
-
if (postcontext !== '') {
|
|
234579
|
-
patch.length1 += postcontext.length;
|
|
234580
|
-
patch.length2 += postcontext.length;
|
|
234581
|
-
if (patch.diffs.length !== 0 &&
|
|
234582
|
-
patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) {
|
|
234583
|
-
patch.diffs[patch.diffs.length - 1][1] += postcontext;
|
|
234584
|
-
} else {
|
|
234585
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, postcontext));
|
|
234586
|
-
}
|
|
234587
|
-
}
|
|
234588
|
-
if (!empty) {
|
|
234589
|
-
patches.splice(++x, 0, patch);
|
|
234590
|
-
}
|
|
234591
|
-
}
|
|
234592
|
-
}
|
|
234593
|
-
};
|
|
234594
|
-
|
|
234595
|
-
|
|
234596
|
-
/**
|
|
234597
|
-
* Take a list of patches and return a textual representation.
|
|
234598
|
-
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|
234599
|
-
* @return {string} Text representation of patches.
|
|
234600
|
-
*/
|
|
234601
|
-
diff_match_patch.prototype.patch_toText = function(patches) {
|
|
234602
|
-
var text = [];
|
|
234603
|
-
for (var x = 0; x < patches.length; x++) {
|
|
234604
|
-
text[x] = patches[x];
|
|
234605
|
-
}
|
|
234606
|
-
return text.join('');
|
|
234607
|
-
};
|
|
234608
|
-
|
|
234609
|
-
|
|
234610
|
-
/**
|
|
234611
|
-
* Parse a textual representation of patches and return a list of Patch objects.
|
|
234612
|
-
* @param {string} textline Text representation of patches.
|
|
234613
|
-
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|
234614
|
-
* @throws {!Error} If invalid input.
|
|
234615
|
-
*/
|
|
234616
|
-
diff_match_patch.prototype.patch_fromText = function(textline) {
|
|
234617
|
-
var patches = [];
|
|
234618
|
-
if (!textline) {
|
|
234619
|
-
return patches;
|
|
234620
|
-
}
|
|
234621
|
-
var text = textline.split('\n');
|
|
234622
|
-
var textPointer = 0;
|
|
234623
|
-
var patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
234624
|
-
while (textPointer < text.length) {
|
|
234625
|
-
var m = text[textPointer].match(patchHeader);
|
|
234626
|
-
if (!m) {
|
|
234627
|
-
throw new Error('Invalid patch string: ' + text[textPointer]);
|
|
234628
|
-
}
|
|
234629
|
-
var patch = new diff_match_patch.patch_obj();
|
|
234630
|
-
patches.push(patch);
|
|
234631
|
-
patch.start1 = parseInt(m[1], 10);
|
|
234632
|
-
if (m[2] === '') {
|
|
234633
|
-
patch.start1--;
|
|
234634
|
-
patch.length1 = 1;
|
|
234635
|
-
} else if (m[2] == '0') {
|
|
234636
|
-
patch.length1 = 0;
|
|
234637
|
-
} else {
|
|
234638
|
-
patch.start1--;
|
|
234639
|
-
patch.length1 = parseInt(m[2], 10);
|
|
234640
|
-
}
|
|
234641
|
-
|
|
234642
|
-
patch.start2 = parseInt(m[3], 10);
|
|
234643
|
-
if (m[4] === '') {
|
|
234644
|
-
patch.start2--;
|
|
234645
|
-
patch.length2 = 1;
|
|
234646
|
-
} else if (m[4] == '0') {
|
|
234647
|
-
patch.length2 = 0;
|
|
234648
|
-
} else {
|
|
234649
|
-
patch.start2--;
|
|
234650
|
-
patch.length2 = parseInt(m[4], 10);
|
|
234651
|
-
}
|
|
234652
|
-
textPointer++;
|
|
234653
|
-
|
|
234654
|
-
while (textPointer < text.length) {
|
|
234655
|
-
var sign = text[textPointer].charAt(0);
|
|
234656
|
-
try {
|
|
234657
|
-
var line = decodeURI(text[textPointer].substring(1));
|
|
234658
|
-
} catch (ex) {
|
|
234659
|
-
// Malformed URI sequence.
|
|
234660
|
-
throw new Error('Illegal escape in patch_fromText: ' + line);
|
|
234661
|
-
}
|
|
234662
|
-
if (sign == '-') {
|
|
234663
|
-
// Deletion.
|
|
234664
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_DELETE, line));
|
|
234665
|
-
} else if (sign == '+') {
|
|
234666
|
-
// Insertion.
|
|
234667
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_INSERT, line));
|
|
234668
|
-
} else if (sign == ' ') {
|
|
234669
|
-
// Minor equality.
|
|
234670
|
-
patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, line));
|
|
234671
|
-
} else if (sign == '@') {
|
|
234672
|
-
// Start of next patch.
|
|
234673
|
-
break;
|
|
234674
|
-
} else if (sign === '') ; else {
|
|
234675
|
-
// WTF?
|
|
234676
|
-
throw new Error('Invalid patch mode "' + sign + '" in: ' + line);
|
|
234677
|
-
}
|
|
234678
|
-
textPointer++;
|
|
234679
|
-
}
|
|
234680
|
-
}
|
|
234681
|
-
return patches;
|
|
234682
|
-
};
|
|
234683
|
-
|
|
234684
|
-
|
|
234685
|
-
/**
|
|
234686
|
-
* Class representing one patch operation.
|
|
234687
|
-
* @constructor
|
|
234688
|
-
*/
|
|
234689
|
-
diff_match_patch.patch_obj = function() {
|
|
234690
|
-
/** @type {!Array.<!diff_match_patch.Diff>} */
|
|
234691
|
-
this.diffs = [];
|
|
234692
|
-
/** @type {?number} */
|
|
234693
|
-
this.start1 = null;
|
|
234694
|
-
/** @type {?number} */
|
|
234695
|
-
this.start2 = null;
|
|
234696
|
-
/** @type {number} */
|
|
234697
|
-
this.length1 = 0;
|
|
234698
|
-
/** @type {number} */
|
|
234699
|
-
this.length2 = 0;
|
|
234700
|
-
};
|
|
234701
|
-
|
|
234702
|
-
|
|
234703
|
-
/**
|
|
234704
|
-
* Emulate GNU diff's format.
|
|
234705
|
-
* Header: @@ -382,8 +481,9 @@
|
|
234706
|
-
* Indices are printed as 1-based, not 0-based.
|
|
234707
|
-
* @return {string} The GNU diff string.
|
|
234708
|
-
*/
|
|
234709
|
-
diff_match_patch.patch_obj.prototype.toString = function() {
|
|
234710
|
-
var coords1, coords2;
|
|
234711
|
-
if (this.length1 === 0) {
|
|
234712
|
-
coords1 = this.start1 + ',0';
|
|
234713
|
-
} else if (this.length1 == 1) {
|
|
234714
|
-
coords1 = this.start1 + 1;
|
|
234715
|
-
} else {
|
|
234716
|
-
coords1 = (this.start1 + 1) + ',' + this.length1;
|
|
234717
|
-
}
|
|
234718
|
-
if (this.length2 === 0) {
|
|
234719
|
-
coords2 = this.start2 + ',0';
|
|
234720
|
-
} else if (this.length2 == 1) {
|
|
234721
|
-
coords2 = this.start2 + 1;
|
|
234722
|
-
} else {
|
|
234723
|
-
coords2 = (this.start2 + 1) + ',' + this.length2;
|
|
234724
|
-
}
|
|
234725
|
-
var text = ['@@ -' + coords1 + ' +' + coords2 + ' @@\n'];
|
|
234726
|
-
var op;
|
|
234727
|
-
// Escape the body of the patch with %xx notation.
|
|
234728
|
-
for (var x = 0; x < this.diffs.length; x++) {
|
|
234729
|
-
switch (this.diffs[x][0]) {
|
|
234730
|
-
case DIFF_INSERT:
|
|
234731
|
-
op = '+';
|
|
234732
|
-
break;
|
|
234733
|
-
case DIFF_DELETE:
|
|
234734
|
-
op = '-';
|
|
234735
|
-
break;
|
|
234736
|
-
case DIFF_EQUAL:
|
|
234737
|
-
op = ' ';
|
|
234738
|
-
break;
|
|
234739
|
-
}
|
|
234740
|
-
text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
|
|
234741
|
-
}
|
|
234742
|
-
return text.join('').replace(/%20/g, ' ');
|
|
234743
|
-
};
|
|
234744
|
-
|
|
234745
|
-
|
|
234746
|
-
// The following export code was added by @ForbesLindesay
|
|
234747
|
-
module.exports = diff_match_patch;
|
|
234748
|
-
module.exports['diff_match_patch'] = diff_match_patch;
|
|
234749
|
-
module.exports['DIFF_DELETE'] = DIFF_DELETE;
|
|
234750
|
-
module.exports['DIFF_INSERT'] = DIFF_INSERT;
|
|
234751
|
-
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
|
|
234752
|
-
} (diffMatchPatch));
|
|
234753
|
-
return diffMatchPatch.exports;
|
|
234754
|
-
}
|
|
234755
|
-
|
|
234756
|
-
var diffMatchPatchExports = requireDiffMatchPatch();
|
|
234757
|
-
|
|
234758
|
-
// --- Diff 데코레이션을 위한 StateEffect 정의 (수정: DecorationSet 타입 명시) ---
|
|
232573
|
+
// --- Diff 데코레이션을 위한 StateEffect 정의 ---
|
|
234759
232574
|
const setAsisDecorationsEffect = StateEffect.define();
|
|
234760
232575
|
const setTobeDecorationsEffect = StateEffect.define();
|
|
234761
232576
|
|
|
234762
232577
|
// --- Diff 데코레이션을 위한 StateField 정의 ---
|
|
234763
232578
|
const asisDiffDecorations = StateField.define({
|
|
234764
232579
|
create() {
|
|
234765
|
-
return Decoration.none;
|
|
232580
|
+
return Decoration.none;
|
|
234766
232581
|
},
|
|
234767
232582
|
update(decorations, tr) {
|
|
234768
|
-
// 트랜잭션의 변화를 데코레이션에 매핑하여 위치가 변경되어도 데코레이션이 유지되도록 함
|
|
234769
232583
|
decorations = decorations.map(tr.changes);
|
|
234770
|
-
// setAsisDecorationsEffect가 있다면 해당 효과의 값을 적용
|
|
234771
232584
|
for (let effect of tr.effects) {
|
|
234772
232585
|
if (effect.is(setAsisDecorationsEffect)) {
|
|
234773
|
-
return effect.value;
|
|
232586
|
+
return effect.value;
|
|
234774
232587
|
}
|
|
234775
232588
|
}
|
|
234776
|
-
return decorations;
|
|
232589
|
+
return decorations;
|
|
234777
232590
|
},
|
|
234778
|
-
provide: f => EditorView.decorations.from(f)
|
|
232591
|
+
provide: f => EditorView.decorations.from(f)
|
|
234779
232592
|
});
|
|
234780
232593
|
|
|
234781
232594
|
const tobeDiffDecorations = StateField.define({
|
|
234782
232595
|
create() {
|
|
234783
|
-
return Decoration.none;
|
|
232596
|
+
return Decoration.none;
|
|
234784
232597
|
},
|
|
234785
232598
|
update(decorations, tr) {
|
|
234786
232599
|
decorations = decorations.map(tr.changes);
|
|
234787
232600
|
for (let effect of tr.effects) {
|
|
234788
232601
|
if (effect.is(setTobeDecorationsEffect)) {
|
|
234789
|
-
return effect.value;
|
|
232602
|
+
return effect.value;
|
|
234790
232603
|
}
|
|
234791
232604
|
}
|
|
234792
232605
|
return decorations;
|
|
@@ -234839,7 +232652,6 @@ class IdeDiff extends HTMLElement {
|
|
|
234839
232652
|
}
|
|
234840
232653
|
|
|
234841
232654
|
disconnectedCallback() {
|
|
234842
|
-
// 컴포넌트 해제 시 스크롤 리스너 제거
|
|
234843
232655
|
if (this._asisScrollHandler) {
|
|
234844
232656
|
this.#asisEditorView.scrollDOM.removeEventListener('scroll', this._asisScrollHandler);
|
|
234845
232657
|
this.#tobeEditorView.scrollDOM.removeEventListener('scroll', this._tobeScrollHandler);
|
|
@@ -234966,41 +232778,37 @@ class IdeDiff extends HTMLElement {
|
|
|
234966
232778
|
this.#tobeEditorView.scrollDOM.addEventListener('scroll', this._tobeScrollHandler);
|
|
234967
232779
|
};
|
|
234968
232780
|
|
|
234969
|
-
// Diff 데코레이션 계산 및 반환 함수
|
|
234970
232781
|
#applyDiffDecorations = (asisSrc, tobeSrc) => {
|
|
234971
|
-
const dmp = new
|
|
232782
|
+
const dmp = new diffMatch_patch.diff_match_patch();
|
|
234972
232783
|
const diffs = dmp.diff_main(asisSrc, tobeSrc);
|
|
234973
232784
|
dmp.diff_cleanupSemantic(diffs);
|
|
234974
232785
|
|
|
234975
232786
|
const asisLineBuilder = new RangeSetBuilder();
|
|
234976
232787
|
const tobeLineBuilder = new RangeSetBuilder();
|
|
234977
232788
|
|
|
234978
|
-
let asisCursor = 0;
|
|
234979
|
-
let tobeCursor = 0;
|
|
232789
|
+
let asisCursor = 0;
|
|
232790
|
+
let tobeCursor = 0;
|
|
234980
232791
|
|
|
234981
|
-
// Decoration 인스턴스 미리 생성
|
|
234982
232792
|
const insertedLineDeco = Decoration.line({ class: "cm-inserted-line-bg" });
|
|
234983
232793
|
const deletedLineDeco = Decoration.line({ class: "cm-deleted-line-bg" });
|
|
234984
232794
|
|
|
234985
232795
|
for (const [op, text] of diffs) {
|
|
234986
|
-
const len = text.length;
|
|
232796
|
+
const len = text.length;
|
|
234987
232797
|
const linesInChunk = text.split('\n');
|
|
234988
232798
|
|
|
234989
232799
|
switch (op) {
|
|
234990
|
-
case
|
|
232800
|
+
case diffMatch_patch.diff_match_patch.DIFF_INSERT:
|
|
234991
232801
|
for (let i = 0; i < linesInChunk.length; i++) {
|
|
234992
|
-
// 마지막 줄이 비어있고 해당 청크가 개행으로 끝나지 않으면 스킵
|
|
234993
232802
|
if (i === linesInChunk.length - 1 && linesInChunk[i] === '' && !text.endsWith('\n')) {
|
|
234994
|
-
tobeCursor += len;
|
|
232803
|
+
tobeCursor += len;
|
|
234995
232804
|
break;
|
|
234996
232805
|
}
|
|
234997
|
-
// Decoration.line은 줄의 시작 위치에만 추가하면 CodeMirror가 해당 줄 전체에 적용합니다.
|
|
234998
232806
|
tobeLineBuilder.add(tobeCursor, tobeCursor, insertedLineDeco);
|
|
234999
232807
|
tobeCursor += linesInChunk[i].length + (i < linesInChunk.length - 1 ? 1 : 0);
|
|
235000
232808
|
}
|
|
235001
232809
|
break;
|
|
235002
232810
|
|
|
235003
|
-
case
|
|
232811
|
+
case diffMatch_patch.diff_match_patch.DIFF_DELETE:
|
|
235004
232812
|
for (let i = 0; i < linesInChunk.length; i++) {
|
|
235005
232813
|
if (i === linesInChunk.length - 1 && linesInChunk[i] === '' && !text.endsWith('\n')) {
|
|
235006
232814
|
asisCursor += len;
|
|
@@ -235011,7 +232819,7 @@ class IdeDiff extends HTMLElement {
|
|
|
235011
232819
|
}
|
|
235012
232820
|
break;
|
|
235013
232821
|
|
|
235014
|
-
case
|
|
232822
|
+
case diffMatch_patch.diff_match_patch.DIFF_EQUAL:
|
|
235015
232823
|
asisCursor += len;
|
|
235016
232824
|
tobeCursor += len;
|
|
235017
232825
|
break;
|
|
@@ -235030,24 +232838,17 @@ class IdeDiff extends HTMLElement {
|
|
|
235030
232838
|
return;
|
|
235031
232839
|
}
|
|
235032
232840
|
|
|
235033
|
-
this.#isScrollSyncActive = false;
|
|
232841
|
+
this.#isScrollSyncActive = false;
|
|
235034
232842
|
|
|
235035
232843
|
let langExtension;
|
|
235036
232844
|
switch(language) {
|
|
235037
232845
|
case 'javascript':
|
|
235038
232846
|
langExtension = javascript();
|
|
235039
232847
|
break;
|
|
235040
|
-
// case 'java':
|
|
235041
|
-
// langExtension = java();
|
|
235042
|
-
// break;
|
|
235043
|
-
// case 'xml':
|
|
235044
|
-
// langExtension = xml();
|
|
235045
|
-
// break;
|
|
235046
232848
|
default:
|
|
235047
|
-
langExtension = javascript();
|
|
232849
|
+
langExtension = javascript();
|
|
235048
232850
|
}
|
|
235049
232851
|
|
|
235050
|
-
// 1단계: 텍스트 내용 변경과 언어 확장을 먼저 디스패치합니다.
|
|
235051
232852
|
this.#asisEditorView.dispatch({
|
|
235052
232853
|
changes: { from: 0, to: this.#asisEditorView.state.doc.length, insert: src1 },
|
|
235053
232854
|
effects: [
|
|
@@ -235062,25 +232863,18 @@ class IdeDiff extends HTMLElement {
|
|
|
235062
232863
|
]
|
|
235063
232864
|
});
|
|
235064
232865
|
|
|
235065
|
-
// 2단계: 텍스트 및 언어 변경이 완전히 적용되고 뷰가 안정화될 시간을 줍니다.
|
|
235066
|
-
// 다음 프레임에서 데코레이션 효과만 별도로 디스패치합니다.
|
|
235067
232866
|
requestAnimationFrame(() => {
|
|
235068
232867
|
const { asisDecorations, tobeDecorations } = this.#applyDiffDecorations(src1, src2);
|
|
235069
232868
|
|
|
235070
232869
|
this.#asisEditorView.dispatch({
|
|
235071
|
-
effects: [setAsisDecorationsEffect.of(asisDecorations)]
|
|
232870
|
+
effects: [setAsisDecorationsEffect.of(asisDecorations)]
|
|
235072
232871
|
});
|
|
235073
232872
|
this.#tobeEditorView.dispatch({
|
|
235074
|
-
effects: [setTobeDecorationsEffect.of(tobeDecorations)]
|
|
232873
|
+
effects: [setTobeDecorationsEffect.of(tobeDecorations)]
|
|
235075
232874
|
});
|
|
235076
232875
|
|
|
235077
|
-
// 3단계: 데코레이션까지 적용된 후 뷰가 다시 안정화될 시간을 한 번 더 줍니다.
|
|
235078
|
-
// 그 다음 프레임에서 스크롤 동기화를 활성화합니다.
|
|
235079
232876
|
requestAnimationFrame(() => {
|
|
235080
232877
|
this.#isScrollSyncActive = true;
|
|
235081
|
-
// 필요하다면 여기서 초기 스크롤 위치를 0으로 리셋하여 정렬을 보장할 수 있습니다.
|
|
235082
|
-
// this.#asisEditorView.scrollDOM.scrollTop = 0;
|
|
235083
|
-
// this.#tobeEditorView.scrollDOM.scrollTop = 0;
|
|
235084
232878
|
});
|
|
235085
232879
|
});
|
|
235086
232880
|
};
|