How to use the diff-match-patch.DIFF_EQUAL function in diff-match-patch

To help you get started, we’ve selected a few diff-match-patch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / diff-match-patch / diff-match-patch-tests.ts View on Github external
diffs.forEach((diff) => {
        const operation = diff[0]; // Operation (insert, delete, equal)
        const text = diff[1]; // Text of change

        switch (operation) {
            case DiffMatchPatch.DIFF_INSERT:
                pattern += "I";
                break;
            case DiffMatchPatch.DIFF_DELETE:
                pattern += "D";
                break;
            case DiffMatchPatch.DIFF_EQUAL:
                pattern += "E";
                break;
        }

        changes += text;
    });
}
github facebookarchive / atom-ide-ui / modules / atom-ide-debugger-python / VendorLib / vs-py-debugger / out / client / common / editor.js View on Github external
break;
            case dmp.DIFF_INSERT:
                if (edit === null) {
                    edit = new Edit(EditAction.Insert, start);
                }
                else if (edit.action === EditAction.Delete) {
                    edit.action = EditAction.Replace;
                }
                // insert and replace edits are all relative to the original state
                // of the document, so inserts should reset the current line/character
                // position to the start.
                line = start.line;
                character = start.character;
                edit.text += diffs[i][1];
                break;
            case dmp.DIFF_EQUAL:
                if (edit !== null) {
                    edits.push(edit);
                    edit = null;
                }
                break;
        }
    }
    if (edit !== null) {
        edits.push(edit);
    }
    return edits;
}
function getTempFileWithDocumentContents(document) {
github inkandswitch / pushpin / src / renderer / components / text-content.js View on Github external
if (oldStr === newStr) {
      return
    }

    // Otherwise find the diff between the current and desired contents, and
    // apply corresponding editor ops to close them.
    log('forceContents')
    const dmp = new DiffMatchPatch()
    const diff = dmp.diff_main(oldStr, newStr)
    // The diff lib doesn't give indicies so we need to compute them ourself as
    // we go along.
    let at = 0
    for (let i = 0; i < diff.length; i += 1) {
      const [type, str] = diff[i]
      switch (type) {
        case DiffMatchPatch.DIFF_EQUAL: {
          at += str.length
          break
        }
        case DiffMatchPatch.DIFF_INSERT: {
          const fromPos = this.codeMirror.posFromIndex(at)
          this.codeMirror.replaceRange(str, fromPos, null, 'automerge')
          at += str.length
          break
        }
        case DiffMatchPatch.DIFF_DELETE: {
          const fromPos = this.codeMirror.posFromIndex(at)
          const toPos = this.codeMirror.posFromIndex(at + str.length)
          this.codeMirror.replaceRange('', fromPos, toPos, 'automerge')
          break
        }
        default: {
github glpi-project / glpi / lib / bundles / jquery-prettytextdiff.js View on Github external
* GLPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GLPI. If not, see .
 * ---------------------------------------------------------------------
 */

// diff-match-patch dependency
// 'diff_match_patch' function and DIFF_* constants have to be declared in global scope
window.diff_match_patch = require('diff-match-patch').diff_match_patch;
window.DIFF_DELETE = require('diff-match-patch').DIFF_DELETE;
window.DIFF_INSERT = require('diff-match-patch').DIFF_INSERT;
window.DIFF_EQUAL = require('diff-match-patch').DIFF_EQUAL;

// PrettyTextDiff jQuery plugin
require('jquery-prettytextdiff');
github imnapo / react-native-cn-richtext-editor / src / CNTextInput.js View on Github external
this.avoidAndroidIssueWhenPressSpaceText = '';
    this.justToolAdded = false;
    this.state = {
      selectedTag: 'body',
      selection: { start: 0, end: 0 },
      avoidUpdateText: false,
    };

    this.dmp = new DiffMatchPatch();
    this.oldText = '';
    this.reCalculateTextOnUpate = false;
    // You can also use the following properties:
    DiffMatchPatch.DIFF_DELETE = -1;
    DiffMatchPatch.DIFF_INSERT = 1;
    DiffMatchPatch.DIFF_EQUAL = 0;
  }
github ForbesLindesay / code-mirror / addon / merge.js View on Github external
var CodeMirror = module.exports = require("code-mirror");
var diff_match_patch = require("diff-match-patch");
var DIFF_INSERT = diff_match_patch.DIFF_INSERT;
var DIFF_DELETE = diff_match_patch.DIFF_DELETE;
var DIFF_EQUAL = diff_match_patch.DIFF_EQUAL;
(function() {
  "use strict";
  // declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL

  var Pos = CodeMirror.Pos;
  var svgNS = "http://www.w3.org/2000/svg";

  function DiffView(mv, type) {
    this.mv = mv;
    this.type = type;
    this.classes = type == "left"
      ? {chunk: "CodeMirror-merge-l-chunk",
         start: "CodeMirror-merge-l-chunk-start",
         end: "CodeMirror-merge-l-chunk-end",
         insert: "CodeMirror-merge-l-inserted",
         del: "CodeMirror-merge-l-deleted",
github buildbuddy-io / buildbuddy / app / compare / diff_chunk.tsx View on Github external
private getInitialState() {
    return { expanded: this.props.chunk.marker === DiffMatchPatch.DIFF_EQUAL && this.props.defaultExpanded };
  }
github Soreine / draft-js-diff / lib / contentBlockDiff.js View on Github external
diffs.forEach(function (diff) {
        var type = diff[0];
        var blockChars = diff[1];

        for (var i = 0; i < blockChars.length; ++i) {
            if (type === diff_match_patch.DIFF_EQUAL) {
                blockDiffs.push({
                    type: type,
                    key1: blockKeys1.get(index1),
                    key2: blockKeys2.get(index2)
                });
                index1++;
                index2++;
            } else if (type === diff_match_patch.DIFF_DELETE) {
                blockDiffs.push({
                    type: type,
                    key1: blockKeys1.get(index1),
                    key2: undefined
                });
                index1++;
            } else {
                blockDiffs.push({
github translate / pootle / pootle / static / js / shared / utils / diff.js View on Github external
export default function diff(a, b) {
  const result = dmp.diff_main(a, b);
  const html = [];

  dmp.diff_cleanupSemantic(result);

  for (let i = 0; i < result.length; i++) {
    const op = result[i][0];
    const text = highlightRO(result[i][1]);
    if (op === DMP.DIFF_INSERT) {
      html[i] = `<span class="diff-insert">${text}</span>`;
    } else if (op === DMP.DIFF_DELETE) {
      html[i] = `<span class="diff-delete">${text}</span>`;
    } else if (op === DMP.DIFF_EQUAL) {
      html[i] = text;
    }
  }

  return html.join('');
}

diff-match-patch

npm package for https://github.com/google/diff-match-patch

Apache-2.0
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis