From ad55f41f5871663dba972f37d9798ab2e9425af5 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Tue, 28 Dec 2021 02:01:08 +0100 Subject: [PATCH] Fixed unstage hunk not working properly when having context lines inbetween changes --- src/main/kotlin/app/git/StatusManager.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/git/StatusManager.kt b/src/main/kotlin/app/git/StatusManager.kt index 6e0aea9..0622ef6 100644 --- a/src/main/kotlin/app/git/StatusManager.kt +++ b/src/main/kotlin/app/git/StatusManager.kt @@ -195,7 +195,9 @@ class StatusManager @Inject constructor( // Restore previously removed lines to the index for (line in removedLines) { - textLines.add(line.newLineNumber + linesAdded, line.text.withoutLineEnding) + // Check how many lines before this one have been deleted + val previouslyRemovedLines = addedLines.count { it.newLineNumber <= line.newLineNumber } - 1 + textLines.add(line.newLineNumber + linesAdded - previouslyRemovedLines, line.text.withoutLineEnding) linesAdded++ }