Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot diff spaces #94

Open
lchthanhth615 opened this issue Jun 5, 2022 · 3 comments
Open

Cannot diff spaces #94

lchthanhth615 opened this issue Jun 5, 2022 · 3 comments

Comments

@lchthanhth615
Copy link

lchthanhth615 commented Jun 5, 2022

"This is text 1" and "this is text [many spaces here] 1" => it can not show diff for spaces.

@mmanela
Copy link
Owner

mmanela commented Jun 6, 2022

It does support that. Let me show you some sample code. The below code will take the example you gave and print out two lines, the old and the new while highlighting any changes. I replace spaces with dots to make it easier to see.

Here is the output
image

Here is the code:

  private static void Main()
        {

            var diffBuilder = new SideBySideDiffBuilder(new Differ());
            var diff = diffBuilder.BuildDiffModel("This is text 1", "This is text       1", ignoreWhitespace: false);

            PrintDiffSide(diff.OldText);
            PrintDiffSide(diff.NewText);
        }

        private static void PrintDiffSide(DiffPaneModel diff)
        {   
            foreach (var line in diff.Lines)
            {
                foreach (var part in line.SubPieces)
                {
                    var partWithSpacesMadeVisible = part.Text.Replace(" ", "·");
                    switch (part.Type)
                    {
                        case ChangeType.Inserted:
                            Console.ForegroundColor = ConsoleColor.Green;
                            break;
                        case ChangeType.Deleted:
                            Console.ForegroundColor = ConsoleColor.Red;
                            break;
                        case ChangeType.Unchanged:
                            Console.ForegroundColor = ConsoleColor.White;
                            break;
                    }
                    Console.Write(partWithSpacesMadeVisible);
                }

            }
            Console.WriteLine();
        }

@lchthanhth615 let me know if you have any questions on this

@lchthanhth615
Copy link
Author

lchthanhth615 commented Jun 7, 2022

Thanks @mmanela for your response.
Not sure why, but I install the plugin from .NET Nugget Manager (DiffPlex.Wpf.1.3.1 and DiffPlex.1.7.1) and using Diff-viewer on WinForm. And I see it cannot show diff for that case:
image

It will work if we replace space to Dot like your example, but it's not make sense in my case.

Could you please help to check ?

@mmanela
Copy link
Owner

mmanela commented Jun 9, 2022

Most likely the WPF control is not exposing the setting to consider white space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants