Skip to content

feat: Added HideUnchangedLines function#11

Open
wojciech-dron wants to merge 1 commit intolzinga:masterfrom
wojciech-dron:hide-exact-lines
Open

feat: Added HideUnchangedLines function#11
wojciech-dron wants to merge 1 commit intolzinga:masterfrom
wojciech-dron:hide-exact-lines

Conversation

@wojciech-dron
Copy link

Added hiding exact lines functionality with show button.

image

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HideUnchangedLines and ContextLines parameters and wires TextDiffPane to 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.

Comment on lines +129 to +136
/// <summary> Creates a visibility state array for each line based on diff changes </summary>
private void CalculateVisibility()
{
if (diff == null || !HideUnchangedLines)
{
visibleLines = null;
return;
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +149 to +151
var contextLinesStart = Math.Max(0, i - ContextLines);
var contextLinesEnd = Math.Min(lineCount - 1, i + ContextLines);

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +247 to +248
Assert.Contains("3 lines hidden", hiddenSummaries[0].TextContent);
Assert.Contains("4 lines hidden", hiddenSummaries[1].TextContent);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Assert.Contains("Line 6", lineTexts);
Assert.DoesNotContain("Line 1", lineTexts);
Assert.DoesNotContain("Line 10", lineTexts);
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
}
}
[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);
}

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

2 participants