Skip to content

Commit

Permalink
Fix undo pasting of multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Dec 30, 2022
1 parent fdcf950 commit 9db4961
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/io/github/jadefalke2/actions/LineAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.jadefalke2.Script;

import java.util.Arrays;
import java.util.stream.IntStream;

public class LineAction implements Action{

Expand Down Expand Up @@ -70,7 +71,7 @@ private void replaceRows(int[] rows, InputLine[] replacement){
if(rows.length < replacement.length) //missing frames -> add emptys that there are enough to replace
insertEmptyRows(replacement.length - rows.length);
if(rows.length > replacement.length) //too many frames -> remove redundant lines
deleteRows(false, Arrays.copyOfRange(rows, replacement.length, rows.length));
deleteRows(Arrays.copyOfRange(rows, replacement.length, rows.length));

for(int i=0;i<replacement.length;i++){
int row = i < rows.length ? rows[i] : rows[rows.length-1] + (i - rows.length) + 1;
Expand All @@ -93,11 +94,12 @@ private void cloneRows(){
}

private void deleteRows(boolean undo){
deleteRows(undo, rows);
int[] toRemove = undo ? IntStream.range(rows[rows.length-1]+1, rows[rows.length-1]+1+replacementLines.length).toArray() : rows;
deleteRows(toRemove);
}
private void deleteRows(boolean undo, int[] rows){
private void deleteRows(int[] rows){
for (int i = rows.length - 1; i >= 0; i--){
int row = undo ? rows[i]+rows.length : rows[i];
int row = rows[i];
script.removeRow(row);
}
}
Expand Down

0 comments on commit 9db4961

Please sign in to comment.