Fix algorithm to move the right amount of cells
This commit is contained in:
@@ -35,24 +35,26 @@ export function moveToCellSequence(targetX: number, targetY: number, bufferServi
|
||||
direction = startX > targetX ? Direction.LEFT : Direction.RIGHT;
|
||||
return repeat(Math.abs(startX - targetX), sequence(direction, applicationCursor));
|
||||
}
|
||||
direction = startY > targetY ? Direction.LEFT : Direction.RIGHT;
|
||||
return repeat(colsFromRowEnd(startY > targetY ? targetX : startX, bufferService), sequence(direction, applicationCursor))
|
||||
+ repeat((Math.abs(startY - targetY) - 1 ) * bufferService.cols, sequence(direction, applicationCursor))
|
||||
+ repeat(colsFromRowBeginning(startY > targetY ? startX : targetX, bufferService), sequence(direction, applicationCursor));
|
||||
direction = startY > targetY ? Direction.LEFT : Direction.RIGHT;
|
||||
const rowDifference = Math.abs(startY - targetY);
|
||||
const cellsToMove = colsFromRowEnd(startY > targetY ? targetX : startX, bufferService) +
|
||||
(rowDifference - 1) * bufferService.cols + 1/*wrap around 1 row*/ +
|
||||
colsFromRowBeginning(startY > targetY ? startX : targetX, bufferService);
|
||||
return repeat(cellsToMove, sequence(direction, applicationCursor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the number of cols from a row beginning to a col.
|
||||
*/
|
||||
function colsFromRowBeginning(currX: number, bufferService: IBufferService): number {
|
||||
return Math.abs(currX);
|
||||
return currX - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the number of cols from a col to row end.
|
||||
*/
|
||||
function colsFromRowEnd(currX: number, bufferService: IBufferService): number {
|
||||
return Math.abs(bufferService.cols - currX);
|
||||
return bufferService.cols - currX;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user