Skip to content

Commit 8bb66fc

Browse files
committed
refactor: fix delete lines recalculation
1 parent 17fb46b commit 8bb66fc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/services/ghost/GhostSuggestions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class GhostSuggestionFile {
7777
}
7878

7979
private computeOperationsOffset(group: GhostSuggestionEditOperation[]) {
80-
return group.reduce(
80+
const { added, removed } = group.reduce(
8181
(acc, op) => {
8282
if (op.type === "+") {
8383
return { added: acc.added + 1, removed: acc.removed }
@@ -88,18 +88,19 @@ class GhostSuggestionFile {
8888
},
8989
{ added: 0, removed: 0 },
9090
)
91+
return { added, removed, offset: added - removed }
9192
}
9293

9394
public deleteSelectedGroup() {
9495
if (this.selectedGroup !== null && this.selectedGroup < this.groups.length) {
9596
const deletedGroup = this.groups.splice(this.selectedGroup, 1)
96-
const { removed } = this.computeOperationsOffset(deletedGroup[0])
97+
const { offset } = this.computeOperationsOffset(deletedGroup[0])
9798
// update deleted operations in the next groups
9899
for (let i = this.selectedGroup; i < this.groups.length; i++) {
99100
for (let j = 0; j < this.groups[i].length; j++) {
100101
const op = this.groups[i][j]
101102
if (op.type === "-") {
102-
op.line = op.line - removed
103+
op.line = op.line + offset
103104
}
104105
}
105106
}

0 commit comments

Comments
 (0)