Skip to content

Commit 50d90f4

Browse files
committed
fix(diff): correct patch application logic and streamline file panel initialization
1 parent e779539 commit 50d90f4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/SingleFileDiffView.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ class SingleFileDiffView(
5555
private val mainPanel: JPanel = JPanel(VerticalLayout(5))
5656
private val myHeaderPanel: JPanel = JPanel(BorderLayout())
5757
private var patchActionPanel: JPanel? = null
58-
private val appliedPatch = GenericPatchApplier.apply(currentFile.readText(), patch.hunks)
5958
private val oldCode = currentFile.readText()
59+
private val appliedPatch = GenericPatchApplier.apply(oldCode, patch.hunks)
60+
private val newCode = appliedPatch?.patchedText
6061

6162
init {
6263
val contentPanel = JPanel(BorderLayout())
@@ -97,15 +98,14 @@ class SingleFileDiffView(
9798
foreground = JBColor(0xFF0000, 0xFF0000)
9899
}
99100

100-
val filePanel: JPanel
101-
if (patch.beforeFileName != null) {
102-
filePanel = JPanel(BorderLayout()).apply {
101+
val filePanel: JPanel = if (patch.beforeFileName != null) {
102+
JPanel(BorderLayout()).apply {
103103
add(filepathLabel, BorderLayout.WEST)
104104
add(addLabel, BorderLayout.CENTER)
105105
add(removeLabel, BorderLayout.EAST)
106106
}
107107
} else {
108-
filePanel = JPanel(BorderLayout()).apply {
108+
JPanel(BorderLayout()).apply {
109109
add(filepathLabel, BorderLayout.WEST)
110110
}
111111
}

0 commit comments

Comments
 (0)