Skip to content

Should diffWordsWithSpace treat consecutive new lines as a single "word"? #211

@attaboy

Description

@attaboy

The behavior of diffWordsWithSpace surprised me with its treatment of consecutive new lines as a single word.

For example:

Left:

A

B

Right:

A
B

Given the above, I would expect this diff:

[{ value: "A\n" }, { value: "\n", removed: true }, { value: "B\n" }]

Instead, I get:

[{ value: "A" }, { value: "\n\n", removed: true}, { value: "\n", added: true}, { value: "B\n" }]

Is this the expected behavior? I would love if it was configurable, because it's A) surprising and, B) if trying to display the diffs visually, it makes changes to new lines seem more complicated than they really are.

(I can see about opening a pull request if a change to this behavior is welcome.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions