GUI: fix moveSelected going out of bounds

This commit is contained in:
tildearrow 2024-11-06 17:49:31 -05:00
parent 5917831992
commit a25b2c7cc8
2 changed files with 73 additions and 6 deletions

View file

@ -1894,6 +1894,73 @@ void FurnaceGUI::doDrag() {
} }
void FurnaceGUI::moveSelected(int x, int y) { void FurnaceGUI::moveSelected(int x, int y) {
SelectionPoint selStartOld, selEndOld, selStartNew, selEndNew;
selStartOld=selStart;
selEndOld=selEnd;
// move selection
DETERMINE_FIRST_LAST;
bool outOfBounds=false;
if (x>0) {
for (int i=0; i<x; i++) {
do {
selStart.xCoarse++;
if (selStart.xCoarse>=lastChannel) {
outOfBounds=true;
break;
}
} while (!e->curSubSong->chanShow[selStart.xCoarse]);
do {
selEnd.xCoarse++;
if (selEnd.xCoarse>=lastChannel) {
outOfBounds=true;
break;
}
} while (!e->curSubSong->chanShow[selEnd.xCoarse]);
if (outOfBounds) break;
}
} else if (x<0) {
for (int i=0; i<-x; i++) {
do {
selStart.xCoarse--;
if (selStart.xCoarse<firstChannel) {
outOfBounds=true;
break;
}
} while (!e->curSubSong->chanShow[selStart.xCoarse]);
do {
selEnd.xCoarse--;
if (selEnd.xCoarse<firstChannel) {
outOfBounds=true;
break;
}
} while (!e->curSubSong->chanShow[selEnd.xCoarse]);
if (outOfBounds) break;
}
}
selStart.y+=y;
selEnd.y+=y;
if (selStart.y<0 || selStart.y>=e->curSubSong->patLen) outOfBounds=true;
if (selEnd.y<0 || selEnd.y>=e->curSubSong->patLen) outOfBounds=true;
selStartNew=selStart;
selEndNew=selEnd;
selStart=selStartOld;
selEnd=selEndOld;
if (outOfBounds) {
return;
}
prepareUndo(GUI_UNDO_PATTERN_DRAG); prepareUndo(GUI_UNDO_PATTERN_DRAG);
// copy and clear // copy and clear
@ -1901,11 +1968,11 @@ void FurnaceGUI::moveSelected(int x, int y) {
logV(_("copy: %s"),c); logV(_("copy: %s"),c);
// move
selStart=selStartNew;
selEnd=selEndNew;
// replace // replace
selStart.xCoarse+=x;
selEnd.xCoarse+=x;
selStart.y+=y;
selEnd.y+=y;
cursor=selStart; cursor=selStart;
doPaste(GUI_PASTE_MODE_NORMAL,0,false,c); doPaste(GUI_PASTE_MODE_NORMAL,0,false,c);