How to use the diff-match-patch.DIFF_DELETE 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 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",
github Webstrates / Webstrates / client / webstrates / coreOpCreator.js View on Github external
patch.diffs.forEach(function([type, value]) {
			switch (type) {
				case diffMatchPatch.DIFF_DELETE:
					ops.push({ sd: value, p: [...path, offset] });
					break;
				case diffMatchPatch.DIFF_INSERT:
					ops.push({ si: value, p: [...path, offset] });
					// falls through intentionally
				case diffMatchPatch.DIFF_EQUAL:
					offset += value.length;
					break;
				default: throw Error(`Unsupported operation type: ${type}`);
			}
		});
	});
github imnapo / react-native-cn-richtext-editor / src / CNTextInput.js View on Github external
this.AvoidAndroidIssueWhenPressSpace = 0;
    this.checkKeyPressAndroid = 0;

    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 buildbuddy-io / buildbuddy / app / compare / diff_chunk.tsx View on Github external
render() {
    const marker = this.props.chunk.marker;
    switch (marker) {
      case DiffMatchPatch.DIFF_INSERT:
        return this.renderChunk(
          this.renderAdded.bind(this),
          /* collapsedLabel= */ "added",
          /* expandButtonClass= */ "added",
          MIN_COLLAPSED_CHANGED_REGION_NUM_LINES
        );
      case DiffMatchPatch.DIFF_DELETE:
        return this.renderChunk(
          this.renderRemoved.bind(this),
          /* collapsedLabel= */ "removed",
          /* expandButtonClass= */ "removed",
          MIN_COLLAPSED_CHANGED_REGION_NUM_LINES
        );
      case DiffMatchPatch.DIFF_EQUAL:
      default:
        return this.renderChunk(
          this.renderUnchanged.bind(this),
          /* collapsedLabel= */ "identical",
          /* expandButtonClass= */ "identical",
          MIN_COLLAPSED_UNCHANGED_REGION_NUM_LINES
        );
    }
  }
github inkandswitch / pushpin / src / renderer / components / text-content.js View on Github external
// 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: {
          throw new Error(`Did not expect diff type ${type}`)
        }
      }
    }
  }
github kythe / kythe / kythe / typescript / languageserver / languageserver / src / document.ts View on Github external
this.refs[i].range.end.character :
                    startChar + refCharLength
              }
            };
          }

        // If anything was deleted, we've made progress through the old file
        // but haven't moved our new position
        case diff.DIFF_DELETE:
          if (newLine) {
            oldPosition.line += diffLineLength;
            oldPosition.character = charOffset;
          } else {
            oldPosition.character += charOffset;
          }
          if (d[0] === diff.DIFF_DELETE) {
            break;
          }

        // If anything was inserted, we've made progress through the new file
        // but haven't moved our old position
        case diff.DIFF_INSERT:
          if (newLine) {
            newPosition.line += diffLineLength;
            newPosition.character = charOffset;
          } else {
            newPosition.character += charOffset;
          }
          break;


        default:
github glpi-project / glpi / lib / bundles / jquery-prettytextdiff.js View on Github external
* (at your option) any later version.
 *
 * 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 akof1314 / CoolFormat / Plugins / VSCode / CoolFormatVSCodePlugin / extension.js View on Github external
line += lines.length - 1;

            if (lines.length > 1) {
                character = lines[lines.length - 1].length;
            } else if (lines.length == 1) {
                character += lines[0].length;
            }

            switch (op) {
                case diffMatchPatch.DIFF_INSERT:
                    editors.push(vscode.TextEdit.insert(start, text));
                    // this new part should not affect counting of original document
                    line = start.line;
                    character = start.character;
                    break;
                case diffMatchPatch.DIFF_DELETE:
                    let end = new vscode.Position(line, character);
                    editors.push(vscode.TextEdit.delete(new vscode.Range(start, end)));
                    break;
                case diffMatchPatch.DIFF_EQUAL:
                    break;
            }
        });
github inkandswitch / pushpin / src / components / code-mirror-editor.jsx View on Github external
// 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: {
          throw new Error(`Did not expect diff type ${type}`)
        }
      }
    }
  }
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({
                    type: type,
                    key1: undefined,
                    key2: blockKeys2.get(index2)
                });
                index2++;
            }
        }
    });

diff-match-patch

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

Apache-2.0
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis