feat: Added HideUnchangedLines function#11
feat: Added HideUnchangedLines function#11wojciech-dron wants to merge 1 commit intolzinga:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a “hide unchanged lines” capability to the TextDiff Blazor component so diffs can collapse large unchanged regions into a summary row with a “show” button, supported by new styling and a corresponding test.
Changes:
- Introduces
HideUnchangedLinesandContextLinesparameters and wiresTextDiffPaneto optionally render hidden-block summary rows. - Adds CSS for the hidden summary row and “show hidden” button (and updates the minified bundle).
- Adds a bUnit test intended to verify unchanged-line hiding behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/BlazorTextDiff.Tests/TextDiffTests.cs | Adds a unit test for hiding unchanged lines. |
| src/BlazorTextDiff/wwwroot/css/BlazorDiff.css | Adds styles for hidden-summary rows and the show button. |
| src/BlazorTextDiff/wwwroot/css/BlazorDiff.min.css | Updates minified CSS to include the new hidden-summary/show-button styles. |
| src/BlazorTextDiff/TextDiffPane.razor | Renders hidden-block summary rows and emits an event to reveal hidden lines. |
| src/BlazorTextDiff/TextDiff.razor | Adds parameters/state and logic intended to compute line visibility and reveal hidden ranges. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// <summary> Creates a visibility state array for each line based on diff changes </summary> | ||
| private void CalculateVisibility() | ||
| { | ||
| if (diff == null || !HideUnchangedLines) | ||
| { | ||
| visibleLines = null; | ||
| return; | ||
| } |
There was a problem hiding this comment.
CalculateVisibility() is never invoked, so setting HideUnchangedLines=true will not change what TextDiffPane renders (and visibleLines will remain null). Call CalculateVisibility() at the end of OnParametersSet() (after computing/post-processing diff), and ensure visibleLines is cleared when diff isn't built.
| var contextLinesStart = Math.Max(0, i - ContextLines); | ||
| var contextLinesEnd = Math.Min(lineCount - 1, i + ContextLines); | ||
|
|
There was a problem hiding this comment.
ContextLines is a public parameter but negative values will produce an empty/invalid context range (and can end up hiding even the changed line). Clamp ContextLines to 0+ (or throw an ArgumentOutOfRangeException) before computing contextLinesStart/contextLinesEnd.
| Assert.Contains("3 lines hidden", hiddenSummaries[0].TextContent); | ||
| Assert.Contains("4 lines hidden", hiddenSummaries[1].TextContent); |
There was a problem hiding this comment.
This test asserts text like "3 lines hidden" / "4 lines hidden", but the component currently renders "@hiddenCount exact lines hidden (show)" inside the summary button. Update the assertions to match the rendered text (or adjust the component copy), otherwise the test will fail even when hiding works.
| Assert.Contains("3 lines hidden", hiddenSummaries[0].TextContent); | |
| Assert.Contains("4 lines hidden", hiddenSummaries[1].TextContent); | |
| Assert.Contains("3 exact lines hidden", hiddenSummaries[0].TextContent); | |
| Assert.Contains("4 exact lines hidden", hiddenSummaries[1].TextContent); |
| Assert.Contains("Line 6", lineTexts); | ||
| Assert.DoesNotContain("Line 1", lineTexts); | ||
| Assert.DoesNotContain("Line 10", lineTexts); | ||
| } |
There was a problem hiding this comment.
The new hide/show feature introduces interactive behavior (the "show" button revealing hidden blocks), but the test only asserts the initial hidden state. Add a test that clicks the .show-hidden-button and verifies the hidden block lines become visible (and/or the summary row disappears) to prevent regressions in the expansion logic.
| } | |
| } | |
| [Fact] | |
| public void HideUnchangedLines_ShowButton_RevealsHiddenBlocks() | |
| { | |
| // Same setup as HideUnchangedLines_HidesExcessContext | |
| var oldText = string.Join("\n", Enumerable.Range(1, 10).Select(i => $"Line {i}")); | |
| var newText = oldText.Replace("Line 5", "Modified Line 5"); | |
| var cut = RenderComponent<TextDiff>(parameters => parameters | |
| .Add(p => p.OldText, oldText) | |
| .Add(p => p.NewText, newText) | |
| .Add(p => p.HideUnchangedLines, true) | |
| .Add(p => p.ContextLines, 1)); | |
| // Click all "show hidden" buttons to expand the hidden blocks | |
| var showButtons = cut.FindAll(".show-hidden-button"); | |
| foreach (var button in showButtons) | |
| { | |
| button.Click(); | |
| } | |
| // After expanding, hidden summaries should be gone | |
| var hiddenSummariesAfterClick = cut.FindAll(".diff-hidden-summary"); | |
| Assert.Empty(hiddenSummariesAfterClick); | |
| // Previously hidden lines should now be visible | |
| var lineTextsAfterClick = cut.FindAll(".line-text").Select(el => el.TextContent).ToList(); | |
| Assert.Contains("Line 1", lineTextsAfterClick); | |
| Assert.Contains("Line 10", lineTextsAfterClick); | |
| } |
Added hiding exact lines functionality with show button.