correct Delete operation behavior

This commit is contained in:
2021-07-27 17:17:34 +08:00
parent e4c6da9990
commit 250dff7107
3 changed files with 38 additions and 18 deletions

View File

@ -191,14 +191,24 @@ namespace BallanceTASEditor.UI {
case OperationEnum.DeleteAfter:
case OperationEnum.DeleteBefore: {
var pos = mSelectionHelp.GetPoint();
pos += oper == OperationEnum.DeleteBefore ? -1 : 1;
if (pos < 0 || pos > mFile.mFrameCount) return;
mFile.Remove(new SelectionRange(pos, pos));
if (oper == OperationEnum.DeleteBefore) pos -= 1; // delete after mean delete current selected item
if (pos < 0 || pos >= mFile.mFrameCount) return;
// only delete before need shift selection
// delete before couldn't cause empty list, so we just need to directly shift
if (oper == OperationEnum.DeleteBefore)
mSelectionHelp.ShiftTo(false);
// also, if we use delete after and delete the tail of item list, we also need to shift pos(use `else if` to prevent double shift)
else if (oper == OperationEnum.DeleteAfter && pos == mFile.mFrameCount) {
// but delete after may cause empty list error(delete the item within only 1 item list)
// so we need prevent this situation
if (mFile.mFrameCount == 1) mSelectionHelp.Reset(); //yes, reset selection to prevent error
else mSelectionHelp.ShiftTo(false); //no, shift selection.
}
// do real operation
mFile.Remove(new SelectionRange(pos, pos));
updateSliderRange();
RefreshDisplay();
}