/*
       * Five types to be split:
       * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
       * <ins>A</ins>X<ins>C</ins><del>D</del>
       * <ins>A</ins><del>B</del>X<ins>C</ins>
       * <ins>A</del>X<ins>C</ins><del>D</del>
       * <ins>A</ins><del>B</del>X<del>C</del>
       */

/*
  * This combines multiple rows where, say, line 1 => line 1, line 2 => line 2, line 3-4 => line 3. That could be
  * reduced to a single connector line 1=4 => line 1-3
  */

/* because endLine is always + 1 */

/* eslint-disable max-len */

/* eslint-disable no-console */

/* eslint-disable no-use-before-define */

/**
   * Compute and return the score for a match with e errors and x location.
   * Accesses loc and pattern through being a closure.
   * @param {number} e Number of errors in match.
   * @param {number} x Location of match.
   * @return {number} Overall score for match (0.0 = good, 1.0 = bad).
   * @private
   */

/**
   * Does a substring of shorttext exist within longtext such that the substring
   * is at least half the length of longtext?
   * Closure, but does not reference any external variables.
   * @param {string} longtext Longer string.
   * @param {string} shorttext Shorter string.
   * @param {number} i Start index of quarter length substring within longtext.
   * @return {Array.<string>} Five element Array, containing the prefix of
   *     longtext, the suffix of longtext, the prefix of shorttext, the suffix
   *     of shorttext and the common middle.  Or null if there was no match.
   * @private
   */

/**
   * Given two strings, compute a score representing whether the internal
   * boundary falls on logical boundaries.
   * Scores range from 6 (best) to 0 (worst).
   * Closure, but does not reference any external variables.
   * @param {string} one First string.
   * @param {string} two Second string.
   * @return {number} The score.
   * @private
   */

/**
   * Split a text into an array of strings.  Reduce the texts to a string of
   * hashes where each Unicode character represents one line.
   * Modifies linearray and linehash through being a closure.
   * @param {string} text String to encode.
   * @return {string} Encoded string.
   * @private
   */

/**
 * @fileoverview Computes the difference between two texts to create a patch.
 * Applies the patch onto another text, allowing for errors.
 * @author fraser@google.com (Neil Fraser)
 */

/**
 * Add some padding on text start and end so that edges can match something.
 * Intended to be called only from within patch_apply.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 * @return {string} The padding string added to each side.
 */

/**
 * Class containing the diff, match and patch methods.
 * @constructor
 */

/**
 * Class representing one diff tuple.
 * ~Attempts to look like a two-element array (which is what this used to be).~
 * Constructor returns an actual two-element array, to allow destructing @JackuB
 * See https://github.com/JackuB/diff-match-patch/issues/14 for details
 * @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.
 * @param {string} text Text to be deleted, inserted, or retained.
 * @constructor
 */

/**
 * Class representing one patch operation.
 * @constructor
 */

/**
 * Compute a list of patches to turn text1 into text2.
 * Use diffs if provided, otherwise compute it ourselves.
 * There are four ways to call this function, depending on what data is
 * available to the caller:
 * Method 1:
 * a = text1, b = text2
 * Method 2:
 * a = diffs
 * Method 3 (optimal):
 * a = text1, b = diffs
 * Method 4 (deprecated, use method 3):
 * a = text1, b = text2, c = diffs
 *
 * @param {string|!Array.<!diff_match_patch.Diff>} a text1 (methods 1,3,4) or
 * Array of diff tuples for text1 to text2 (method 2).
 * @param {string|!Array.<!diff_match_patch.Diff>=} opt_b text2 (methods 1,4) or
 * Array of diff tuples for text1 to text2 (method 3) or undefined (method 2).
 * @param {string|!Array.<!diff_match_patch.Diff>=} opt_c Array of diff tuples
 * for text1 to text2 (method 4) or undefined (methods 1,2,3).
 * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
 */

/**
 * Compute and return the destination text (all equalities and insertions).
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @return {string} Destination text.
 */

/**
 * Compute and return the source text (all equalities and deletions).
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @return {string} Source text.
 */

/**
 * Compute the Levenshtein distance; the number of inserted, deleted or
 * substituted characters.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @return {number} Number of changes.
 */

/**
 * Convert a diff array into a pretty HTML report.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @return {string} HTML representation.
 */

/**
 * Crush the diff into an encoded string which describes the operations
 * required to transform text1 into text2.
 * E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
 * Operations are tab-separated.  Inserted text is escaped using %xx notation.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @return {string} Delta text.
 */

/**
 * Determine if the suffix of one string is the prefix of another.
 * @param {string} text1 First string.
 * @param {string} text2 Second string.
 * @return {number} The number of characters common to the end of the first
 *     string and the start of the second string.
 * @private
 */

/**
 * Determine the common prefix of two strings.
 * @param {string} text1 First string.
 * @param {string} text2 Second string.
 * @return {number} The number of characters common to the start of each
 *     string.
 */

/**
 * Determine the common suffix of two strings.
 * @param {string} text1 First string.
 * @param {string} text2 Second string.
 * @return {number} The number of characters common to the end of each string.
 */

/**
 * Diff Match and Patch
 * Copyright 2018 The diff-match-patch Authors.
 * https://github.com/google/diff-match-patch
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Do a quick line-level diff on both strings, then rediff the parts for
 * greater accuracy.
 * This speedup can produce non-minimal diffs.
 * @param {string} text1 Old string to be diffed.
 * @param {string} text2 New string to be diffed.
 * @param {number} deadline Time when the diff should be complete by.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 * @private
 */

/**
 * Do the two texts share a substring which is at least half the length of the
 * longer text?
 * This speedup can produce non-minimal diffs.
 * @param {string} text1 First string.
 * @param {string} text2 Second string.
 * @return {Array.<string>} Five element Array, containing the prefix of
 *     text1, the suffix of text1, the prefix of text2, the suffix of
 *     text2 and the common middle.  Or null if there was no match.
 * @private
 */

/**
 * Emulate GNU diff's format.
 * Header: @@ -382,8 +481,9 @@
 * Indices are printed as 1-based, not 0-based.
 * @return {string} The GNU diff string.
 */

/**
 * Find the 'middle snake' of a diff, split the problem in two
 * and return the recursively constructed diff.
 * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
 * @param {string} text1 Old string to be diffed.
 * @param {string} text2 New string to be diffed.
 * @param {number} deadline Time at which to bail if not yet complete.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 * @private
 */

/**
 * Find the differences between two texts.  Assumes that the texts do not
 * have any common prefix or suffix.
 * @param {string} text1 Old string to be diffed.
 * @param {string} text2 New string to be diffed.
 * @param {boolean} checklines Speedup flag.  If false, then don't run a
 *     line-level diff first to identify the changed areas.
 *     If true, then run a faster, slightly less optimal diff.
 * @param {number} deadline Time when the diff should be complete by.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 * @private
 */

/**
 * Find the differences between two texts.  Simplifies the problem by stripping
 * any common prefix or suffix off the texts before diffing.
 * @param {string} text1 Old string to be diffed.
 * @param {string} text2 New string to be diffed.
 * @param {boolean=} opt_checklines Optional speedup flag. If present and false,
 *     then don't run a line-level diff first to identify the changed areas.
 *     Defaults to true, which does a faster, slightly less optimal diff.
 * @param {number=} opt_deadline Optional time when the diff should be complete
 *     by.  Used internally for recursive calls.  Users should set DiffTimeout
 *     instead.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 */

/**
 * Given an array of patches, return another array that is identical.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
 */

/**
 * Given the location of the 'middle snake', split the diff in two parts
 * and recurse.
 * @param {string} text1 Old string to be diffed.
 * @param {string} text2 New string to be diffed.
 * @param {number} x Index of split point in text1.
 * @param {number} y Index of split point in text2.
 * @param {number} deadline Time at which to bail if not yet complete.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 * @private
 */

/**
 * Given the original text1, and an encoded string which describes the
 * operations required to transform text1 into text2, compute the full diff.
 * @param {string} text1 Source string for the diff.
 * @param {string} delta Delta text.
 * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
 * @throws {!Error} If invalid input.
 */

/**
 * Increase the context until it is unique,
 * but don't let the pattern expand beyond Match_MaxBits.
 * @param {!diff_match_patch.patch_obj} patch The patch to grow.
 * @param {string} text Source text.
 * @private
 */

/**
 * Initialise the alphabet for the Bitap algorithm.
 * @param {string} pattern The text to encode.
 * @return {!Object} Hash of character locations.
 * @private
 */

/**
 * Locate the best instance of 'pattern' in 'text' near 'loc' using the
 * Bitap algorithm.
 * @param {string} text The text to search.
 * @param {string} pattern The pattern to search for.
 * @param {number} loc The location to search around.
 * @return {number} Best match index or -1.
 * @private
 */

/**
 * Locate the best instance of 'pattern' in 'text' near 'loc'.
 * @param {string} text The text to search.
 * @param {string} pattern The pattern to search for.
 * @param {number} loc The location to search around.
 * @return {number} Best match index or -1.
 */

/**
 * Look for single edits surrounded on both sides by equalities
 * which can be shifted sideways to align the edit to a word boundary.
 * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 */

/**
 * Look through the patches and break up any which are longer than the maximum
 * limit of the match algorithm.
 * Intended to be called only from within patch_apply.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 */

/**
 * Merge a set of patches onto the text.  Return a patched text, as well
 * as a list of true/false values indicating which patches were applied.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 * @param {string} text Old text.
 * @return {!Array.<string|!Array.<boolean>>} Two element Array, containing the
 *      new text and an array of boolean values.
 */

/**
 * Parse a textual representation of patches and return a list of Patch objects.
 * @param {string} textline Text representation of patches.
 * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
 * @throws {!Error} If invalid input.
 */

/**
 * Reduce the number of edits by eliminating operationally trivial equalities.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 */

/**
 * Reduce the number of edits by eliminating semantically trivial equalities.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 */

/**
 * Rehydrate the text in a diff from a string of line hashes to real lines of
 * text.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @param {!Array.<string>} lineArray Array of unique strings.
 * @private
 */

/**
 * Reorder and merge like edit sections.  Merge equalities.
 * Any edit section can move as long as it doesn't cross an equality.
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 */

/**
 * Search for element in parent and create it if it can't be found
 * @param {*HTMLElement} parent
 * @param {string} elClass Element class
 *
 * Returns ID of the element
 */

/**
 * Simple is object check.
 * @param item
 * @returns {boolean}
 */

/**
 * Split two texts into an array of strings.  Reduce the texts to a string of
 * hashes where each Unicode character represents one line.
 * @param {string} text1 First string.
 * @param {string} text2 Second string.
 * @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
 *     An object containing the encoded text1, the encoded text2 and
 *     the array of unique strings.
 *     The zeroth element of the array of unique strings is intentionally blank.
 * @private
 */

/**
 * Take a list of patches and return a textual representation.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 * @return {string} Text representation of patches.
 */

/**
 * The data structure representing a diff is an array of tuples:
 * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
 * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
 */

/**
 * loc is a location in text1, compute and return the equivalent location in
 * text2.
 * e.g. 'The cat' vs 'The big cat', 1->1, 5->8
 * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
 * @param {number} loc Location within text1.
 * @return {number} Location within text2.
 */

/**
 // eslint-disable-next-line max-len
 * This method takes the raw diffing info from the Google lib and returns a nice clean object of the following
 * form:
 * {
 *   leftStartLine:
 *   leftEndLine:
 *   rightStartLine:
 *   rightEndLine:
 * }
 *
 * Ultimately, that's all the info we need to highlight the appropriate lines in the left + right editor, add the
 * SVG connectors, and include the appropriate <<, >> arrows.
 *
 * Note: leftEndLine and rightEndLine are always the start of the NEXT line, so for a single line diff, there will
 * be 1 separating the startLine and endLine values. So if leftStartLine === leftEndLine or rightStartLine ===
 * rightEndLine, it means that new content from the other editor is being inserted and a single 1px line will be
 * drawn.
 */

/**
* Deep merge two objects.
* @param target
* @param source
*/

/** @type {!Array.<!diff_match_patch.Diff>} */

/** @type {?number} */

/** @type {number} */

/** @type {string} */

/***/

//

//    we DO want to make it a full line

//   -> <del>abc</del>xxx<ins>def</ins>

//   -> <ins>def</ins>xxx<del>abc</del>

//  DIFF FUNCTIONS

//  MATCH FUNCTIONS

//  PATCH FUNCTIONS

//  p1   p2

//  p3   p4

// '\x00' is a valid character, but various debuggers don't like it.

// 'this' becomes 'window' in a closure.

// 'whitespace'.  Since this function's purpose is largely cosmetic,

// +1 for the newline char

// +1 needed for newline char

// 1. where a completely fresh new line is being inserted in left editor, we want the line on right to stay a 1px line

// 1.0 = very loose).  Note that Match_Threshold controls how closely the

// 1.0 to the score (0.0 is a perfect match).

// 2. where a new character is inserted at the start of a newline on the left but the line contains other stuff,

// 20, but the first patch was found at 12, delta is 2 and the second patch

// A deletion and an insertion is one substitution.

// A half-match was found, sort out the return data.

// A match this many characters away from the expected location will add

// A new patch starts here.

// Add a dummy entry at the end.

// Add nullPadding equality.

// Add one chunk for good luck.

// Add some padding on end of last diff.

// Add some padding on start of first diff.

// Add the prefix.

// Add the remaining character length.

// Add the suffix.

// After the previous speedup, the character can't be an equality.

// All connectors, regardless of ltr or rtl

// Allocate 2/3rds of the space for text1, the rest for text2.

// Already passed loc, downhill from here on in.

// An insertion or deletion.

// Anything else is an error.

// Append the end context for this patch.

// At what point is no match declared (0.0 = perfection, 1.0 = very loose).

// Bail out at 65535 because

// Binary search.

// Blank tokens are ok (from a trailing \t).

// Both matched.  Select the longest.

// Bump all the patches forward.

// But check anyway.

// Cache the text lengths to prevent multiple calls.

// Can't find valid trailing context.  Drop this patch.

// Candidate found.

// Change second copy to insert.

// Check again based on the third quarter.

// Check for equality (speedup).

// Check for null inputs.

// Check to see if the problem can be split in two.

// Chunk size for context length.

// Compute diffs from text1 and text2.

// Compute text1 from diffs.

// Compute the diff on the middle block.

// Compute the head context for the next patch.

// Convert the diff back to original text.

// Cost of an empty edit operation in terms of edit characters.

// Create one of several smaller patches.

// Current instance we pass around to other functions

// Deep copy the patches so that no changes are made to originals.

// Defaults.

// Define some regex patterns for matching boundaries.

// Delete the offending records and add the merged ones.

// Deletion

// Deletion or equality.  Only take as much as we can stomach.

// Deletion.

// Diff took too long and hit the deadline or

// Diffing library

// Don't risk returning a non-optimal diff if we have unlimited time.

// Duplicate record.

// Each port of this function behaves slightly differently due to

// Each token begins with a one character parameter which specifies the

// Edges are the best.

// Eliminate an equality that is smaller or equal to the edits on both

// Eliminate freak matches (e.g. blank lines)

// Eliminate the null case.

// Ensure instance is a constructor with `new`

// Equality found.

// Equality or deletion.

// Equality or insertion.

// Escape the body of the patch with %xx notation.

// Extend the lengths.

// Factor out any common prefixies.

// Factor out any common suffixies.

// Fall through.

// Find any overlaps between deletions and insertions.

// First check if the second quarter is the seed for a half-match.

// First pass: exact match.

// Fix for #28 https://github.com/ace-diff/ace-diff/issues/28

// Found a match.  :)

// Get rid of the null case.

// Grow first equality.

// Grow last equality.

// Highest score beyond which we give up.

// How far to search for a match (0 = exact location, 1000+ = broad match).

// If shifts were made, the diff needs reordering and another shift sweep.

// If the total number of characters is odd, then the front path will collide

// Imperfect match.  Run a diff to get a framework of equivalent

// Initialise the alphabet.

// Initialise the bit arrays.

// Insert an equality and swap and trim the surrounding edits.

// Insertion

// Insertion.

// Insertions are harmless.

// Intentionally ignore the first and last element (don't need checking).

// Is there a nearby exact match? (speedup)

// Just add some text (speedup).

// Just delete some text (speedup).

// Look for the first and last matches of pattern in text.  If two different

// M,N are the first curve control point, O,P the second control point

// Making deep copies is hard in JavaScript.

// Malformed URI sequence.

// Merge the results.

// Merge this equality with the previous one.

// Method 1: text1, text2

// Method 2: diffs

// Method 3: text1, diffs

// Method 4: text1, text2, diffs

// Minor equality.

// Mirror x2 onto top-left coordinate system.

// Modifying text would create many large strings to garbage collect.

// No changes made which could affect previous entry, keep going.

// No hope for a (better) match at greater error levels.

// No match found.  :(

// Normalize the diff.

// Not a candidate, and can never become one.

// Number of seconds to map a diff before giving up (0 for infinity).

// Only extract an overlap if it is as big as the edit ahead or behind it.

// Operation (insert, delete, equal)

// Overlap detected.

// Overlap found.  Insert an equality and trim the surrounding edits.

// Perfect match, just shove the replacement text in.

// Performance analysis: https://neil.fraser.name/news/2007/10/09/

// Performance analysis: https://neil.fraser.name/news/2010/11/04/

// Pick up the leftover patch if not empty.

// Pointless.

// Quick check for common null cases.

// Quick check for the worst case.

// Ran off the bottom of the graph.

// Ran off the left of the graph.

// Ran off the right of the graph.

// Ran off the top of the graph.

// Range module placeholder

// Redefine these in your program to override the defaults.

// Rediff any replacement blocks, this time character-by-character.

// Remove the big old patch.

// Remove the dummy entry at the end.

// Reset the counters.

// Restore the prefix and suffix.

// Reverse overlap found.

// Roll back the start points.

// Run a binary search to determine how far from 'loc' we can stray at this

// Scan for the best match; each iteration allows for one more error.

// Scan the text on a line-by-line basis first.

// Second pass: look for single edits surrounded on both sides by equalities

// Second, step character by character right, looking for the best fit.

// Set a deadline by which time the diff must be complete.

// Setting all elements to -1 is faster in Chrome & Firefox than mixing

// Shift the edit over the next equality.

// Shift the edit over the previous equality.

// Shorter text is inside the longer text (speedup).

// Should be 0.

// Single character string.

// Small equality inside a patch.

// So we'll insert a junk entry to avoid generating a null character.

// Start by looking for a single character match

// Start of next patch.

// Start with a 1/4 length substring at position i as a seed.

// String.fromCharCode(65536) == String.fromCharCode(0)

// Strip the padding off.

// Subtract the delta for this failed patch from subsequent patches.

// Swap insertions for deletions if diff is reversed.

// TODO this should re-init gutter

// The >= encourages trailing rather than leading whitespace on edits.

// The alphabet (s) is a sparse hash, so the following line generates

// The end points match, but the content is unacceptably bad.

// The following export code was added by @ForbesLindesay

// The lineHeight is set to 0 initially and we need to wait for another tick to get it

// The number of bits in an int.

// This is a large deletion.  Let it pass in one chunk.

// This is a single edit surrounded by equalities.

// This is of the form "C M,N O,P Q,R" where C is a directive for SVG ("curveto"),

// This match will almost certainly be better than any existing match.

// Throw away the equality we just deleted.

// Throw away the equality we just deleted;

// Throw away the previous equality (it needs to be reevaluated).

// Throw away the previous equality.

// Thus moving the diff() with it

// Told you so.

// Trim off common prefix (speedup).

// Trim off common suffix (speedup).

// Truncate the longer string.

// Unlike Unidiff, our patch lists have a rolling context.

// Update prepatch text & pos to reflect the application of the

// Update the current character count.

// Upon reaching an equality, check for prior redundancies.

// Use the result from this iteration as the maximum for the next.

// WTF?

// Walk the front path one step.

// Walk the reverse path one step.

// Walk the text, pulling out a substring for each line.

// Was the location was deleted?

// We have an improvement, save it back to the diff.

// What about in the other direction? (speedup)

// When deleting a large block of text (over ~64 characters), how close do

// When passing loc, don't exceed our current distance from loc.

// a monster delete.

// acediff.editors.left.ace.getSession().getLength() * acediff.lineHeight

// allows on-the-fly changes to the AceDiff instance settings

// and Q,R are the final coords

// and increase length until no match is found.

// as the first char for a diff, other times not - and it would change when you were typing on-the-fly. This

// assumption: both editors have same line heights

// back from google as being on the last char of the previous line so we need to bump it up one

// but just to be safe, it's included

// called onscroll. Updates the gap to ensure the connectors are all lining up

// can this occur? Just in case.

// clear out any single line diffs (i.e. single line on both editors)

// creates two contains for positioning the copy left + copy right arrows

// delta keeps track of the offset between the expected and actual location

// dense, but this accommodates two scenarios:

// destroy the two editors

// e.g. lineArray[4] == 'Hello\n'

// e.g. lineHash['Hello\n'] == 4

// e.g: <del>abcxxx</del><ins>xxxdef</ins>

// e.g: <del>xxxabc</del><ins>defxxx</ins>

// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC

// editor content

// editorHeight: document.getElementById(acediff.options.left.id).clientHeight

// end points of a delete need to match.

// error level.

// exposes the Ace editors in case the dev needs it

// figure out. This feels like the hardest part of the entire script.

// fussy function

// generates a Bezier curve in SVG format

// going to be used as the start line for the diff though.

// has an effective expected position of 22.

// have the same point system, even if p1 === p3 or p2 === p4

// helper to return the startline, endline, startChar and endChar for a diff in a particular editor. Pretty

// https://github.com/google/diff-match-patch/wiki/Unidiff

// if the end char is the first char on the line, we don't want to highlight that extra line

// if the start char is the final char on the line, it's a newline & we ignore it

// if we're dealing with too many diffs, fail silently

// indices.

// instantiate the editors in an internal data structure

// integers and undefined.

// is used to level things out so the diffs don't appear to shift around

// just completed patch.

// keep track of the scroll height

// loop through all grouped diffs. If this new diff lies between an existing one, we'll just add to it, rather

// matches are found, increase the pattern length.

// not implemented yet

// note that this and everything else in this script uses 0-indexed row numbers

// now create the curve

// number of diffs equals number of characters, no commonality at all.

// oddly, occasionally the algorithm returns a diff with no changes made

// of the previous patch.  If there are patches expected at positions 10 and

// operation of this token (delete, insert, equality).

// our constructor

// our main diffing function. I actually don't think this needs to exposed: it's called automatically,

// our public API

// parse the raw diff into something a little more palatable

// patch_splitMax will only provide an oversized pattern in the case of

// position it at the initial x,y coords

// pretty confident this returns the right stuff for the left editor: start & end line & char

// rather than force total conformity.

// reposition the copy containers containing all the arrows

// set up the editors

// shows a diff in one of the two editors.

// sides of it.

// simplify our computed diffs; this groups together multiple diffs on subsequent lines

// store the visible height of the editors (assumed the same)

// subtle differences in each language's definition of things like

// text.split('\n') would would temporarily double our memory footprint.

// text2 is not used.

// than create a new one

// that will store a little info about the diffs and

// the choice has been made to use each language's native features

// the contents have to be to match the expected contents. (0.0 = perfection,

// this is necessary because if a new diff starts on the FIRST char of the left editor, the diff can comes

// this is the ACTUAL undoctored current line in the other editor. It's always right. Doesn't mean it's

// this was added in to hack around an oddity with the Google lib. Sometimes it would include a newline

// to get Ace to highlight the full row we just set the start and end chars to 0 and 1

// update the existing grouped diff to expand its horizons to include this new diff start + end lines

// warnings.

// whether or not this diff is a plain INSERT into the other editor, or overwrites a line take a little work to

// which can be shifted sideways to eliminate an equality.

// with the reverse path.
