Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 24, 2025

Problem

The unified view in Diffly was only displaying the new version of changed lines, making it impossible for users to see what the original text looked like. This defeated the purpose of a diff tool, as users couldn't understand what actually changed.

Before:

  1   1   line 1
  2   2 ~ new line 2    <- Only shows new version, old text is hidden
  3   3   line 3

Solution

Modified UnifiedCharDiffText.kt to properly handle DiffType.CHANGED entries by displaying both the old and new versions of changed lines, following standard unified diff format:

After:

  1   1   line 1
  2     - old line 2    <- Shows old version with deletion styling
      2 + new line 2    <- Shows new version with addition styling  
  3   3   line 3

Key Changes

  • Two-line rendering for changes: For DiffType.CHANGED entries, now renders both old line (with - prefix) and new line (with + prefix)
  • Proper syntax highlighting: Both old and new lines receive syntax highlighting when enabled
  • Character-level diffs preserved: New lines still show character-level differences when available
  • Correct line numbering: Old line numbers for deletion entries, new line numbers for addition entries
  • Visual distinction: Uses appropriate background colors (red for deletions, green for additions)

Testing

Added UnifiedCharDiffTextTest.kt to verify the logic handles all diff types correctly and produces the expected unified diff format.

Fixes #3.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4608m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/lib/gradle-daemon-main-8.11.1.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/lib/agents/gradle-instrumentation-agent-8.11.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.11.1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@JahidHasanCO JahidHasanCO marked this pull request as ready for review July 24, 2025 08:42
@github-advanced-security
Copy link
Contributor

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copilot AI and others added 3 commits July 24, 2025 08:45
Co-authored-by: JahidHasanCO <50579963+JahidHasanCO@users.noreply.github.com>
Co-authored-by: JahidHasanCO <50579963+JahidHasanCO@users.noreply.github.com>
Co-authored-by: JahidHasanCO <50579963+JahidHasanCO@users.noreply.github.com>
Text(
text = oldLineNumber.toString(),
modifier = Modifier
.width(40.dp)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
Text(
text = "",
modifier = Modifier
.width(40.dp)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
// Prefix for deletion
Text(
text = "-",
modifier = Modifier.padding(end = 4.dp),

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
Text(
text = "",
modifier = Modifier
.width(40.dp)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
Text(
text = newLineNumber.toString(),
modifier = Modifier
.width(40.dp)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
Text(text = entry.newLine?.let { newLineNumber.toString() }
?: "",
modifier = Modifier
.width(40.dp)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
// Prefix
Text(
text = prefix,
modifier = Modifier.padding(end = 4.dp),

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
@@ -0,0 +1,108 @@
package dev.jahidhasanco.diffly.presentation.component

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning test

The file /home/runner/work/diffly/diffly/app/src/test/java/dev/jahidhasanco/diffly/presentation/component/UnifiedCharDiffTextTest.kt is not ending with a new line.
class UnifiedCharDiffTextTest {

@Test
fun testUnifiedViewLogicWithChangedEntries() {

Check warning

Code scanning / detekt

One method should have one responsibility. Long methods tend to handle many things at once. Prefer smaller methods to make them easier to understand. Warning test

The function testUnifiedViewLogicWithChangedEntries is too long (78). The maximum length is 60.
}
DiffType.UNCHANGED -> {
val line = entry.oldLine ?: ""
renderedLines.add("${oldLineNumber.toString().padStart(3)} ${newLineNumber.toString().padStart(3)} $line")

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning test

Line detected that is longer than the defined maximum line length in the code style.
Copilot AI changed the title [WIP] Syntax highlighting in unified view does not show old text of line Fix unified view to show both old and new text for changed lines with syntax highlighting Jul 24, 2025
Copilot AI requested a review from JahidHasanCO July 24, 2025 08:52
@JahidHasanCO JahidHasanCO merged commit a1976e9 into main Jul 24, 2025
6 checks passed
@JahidHasanCO JahidHasanCO deleted the copilot/fix-3 branch July 24, 2025 09:12
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.

Syntax highlighting in unified view does not show old text of line

2 participants