๐Ÿ› merge view diff bug for appended text with new line

the reproducible bug code and example can be viewed here online.

issue

  • I want to show diff view for two texts; the new text only append some text with new line in it.
  • the diff view is expected to show only one added green new line without deleted red old line

  • Could you please update the diff algorithm to correct this?
const doc = `line11
line12
line13
line14
line15
examples are strings with op
new line after will highlight current line`;

const docAppended = doc+'\nSix';

 const editor = new EditorView({
      extensions: [
        basicSetup,
        unifiedMergeView({
          original: doc,
          gutter: true,
          highlightChanges: false,
          syntaxHighlightDeletions: true,
          mergeControls: false,
        }),
      ],
      doc: docAppended,
      parent: document.body
    });

This is intentional behavior. Our changed chunk representation cannot have one side of the chunkโ€™s range be outside of the document, and since thereโ€™s no valid document position beyond that last line, we must include that line (see this issue).

  • this issue seems to only happen at the last line in the diff view. I never have this problem in the middle of diff view

    • If so, we can keep the diff algorithm logic unchanged and only change the render logic to make the diff view visually correct
  • :bulb: I have an idea,

    • in state field deletedChunks.update , when buildDeletedChunks, ignore the last chunk to hide the unexpected red deleted line (the line above line7 in pic)
    • in view plugin decorateChunks.update, when iterating change chunks, if itโ€™s the second-to-last chunk, ignore buildChunkDeco for it to hide the unexpected green background ( line7 in pic) because itโ€™s unchanged visually
  • :thinking: What do you think of my solution?