src/index.js
function getSingleDiffInfo(editor, offset, diffString) {
  const info = {
    startLine: 0,
    startChar: 0,
    endLine: 0,
    endChar: 0,
  };
  const endCharNum = offset + diffString.length;
  let runningTotal = 0;
  let startLineSet = false,
    endLineSet = false;

  editor.lineLengths.forEach((lineLength, lineIndex) => {
    runningTotal += lineLength;

    if (!startLineSet && offset < runningTotal) {
      info.startLine = lineIndex;
      info.startChar = offset - runningTotal + lineLength;
      startLineSet = true;
    }

    if (!endLineSet && endCharNum <= runningTotal) {
      info.endLine = lineIndex;
      info.endChar = endCharNum - runningTotal + lineLength;
      endLineSet = true;
    }
  });

  // if the start char is the final char on the line, it's a newline & we ignore it
  if (info.startChar > 0 && getCharsOnLine(editor, info.startLine) === info.startChar) {
    info.startLine++;
    info.startChar = 0;
  }

  // if the end char is the first char on the line, we don't want to highlight that extra line
  if (info.endChar === 0) {
    info.endLine--;
  }

  const endsWithNewline = /\n$/.test(diffString);
  if (info.startChar > 0 && endsWithNewline) {
    info.endLine++;
  }

  return info;
}
function getSingleDiffInfo(editor, offset, diffString) {
  const info = {
    startLine: 0,
    startChar: 0,
    endLine: 0,
    endChar: 0,
  };
  const endCharNum = offset + diffString.length;
  let runningTotal = 0;
  let startLineSet = false,
    endLineSet = false;

  editor.lineLengths.forEach((lineLength, lineIndex) => {
    runningTotal += lineLength;

    if (!startLineSet && offset < runningTotal) {
      info.startLine = lineIndex;
      info.startChar = offset - runningTotal + lineLength;
      startLineSet = true;
    }

    if (!endLineSet && endCharNum <= runningTotal) {
      info.endLine = lineIndex;
      info.endChar = endCharNum - runningTotal + lineLength;
      endLineSet = true;
    }
  });

  // if the start char is the final char on the line, it's a newline & we ignore it
  if (info.startChar > 0 && getCharsOnLine(editor, info.startLine) === info.startChar) {
    info.startLine++;
    info.startChar = 0;
  }

  // if the end char is the first char on the line, we don't want to highlight that extra line
  if (info.endChar === 0) {
    info.endLine--;
  }

  const endsWithNewline = /\n$/.test(diffString);
  if (info.startChar > 0 && endsWithNewline) {
    info.endLine++;
  }

  return info;
}
function getSingleDiffInfo ( editor , offset , diffString ) { const info = { startLine : 0 , startChar : 0 , endLine : 0 , endChar : 0 , } ; const endCharNum = offset + diffString . length ; let runningTotal = 0 ; let startLineSet = false , endLineSet = false ; editor . lineLengths . forEach ( ( lineLength , lineIndex ) => { runningTotal += lineLength ; if ( ! startLineSet && offset < runningTotal ) { info . startLine = lineIndex ; info . startChar = offset - runningTotal + lineLength ; startLineSet = true ; } if ( ! endLineSet && endCharNum <= runningTotal ) { info . endLine = lineIndex ; info . endChar = endCharNum - runningTotal + lineLength ; endLineSet = true ; } } ) ; // if the start char is the final char on the line, it's a newline & we ignore it if ( info . startChar > 0 && getCharsOnLine ( editor , info . startLine ) === info . startChar ) { info . startLine ++ ; info . startChar = 0 ; } // if the end char is the first char on the line, we don't want to highlight that extra line if ( info . endChar === 0 ) { info . endLine -- ; } const endsWithNewline = / \n$ / . test ( diffString ) ; if ( info . startChar > 0 && endsWithNewline ) { info . endLine ++ ; } return info ; }
helper to return the startline, endline, startChar and endChar for a diff in a particular editor. Pretty fussy function
helper to return the startline endline startChar and endChar for a diff in a particular editor . Pretty fussy function