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

@ -211,7 +211,7 @@ void FurnaceGUI::finishSelection() {
}
void FurnaceGUI::moveCursor(int x, int y, bool select) {
if (y>=editStepCoarse || y<=-editStepCoarse || x<=-5 || x>=5 ) {
if (y>=editStepCoarse || y<=-editStepCoarse || x<=-5 || x>=5) {
makeCursorUndo();
}
if (!select) {

View file

@ -1894,6 +1894,73 @@ void FurnaceGUI::doDrag() {
}
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);
// copy and clear
@ -1901,11 +1968,11 @@ void FurnaceGUI::moveSelected(int x, int y) {
logV(_("copy: %s"),c);
// move
selStart=selStartNew;
selEnd=selEndNew;
// replace
selStart.xCoarse+=x;
selEnd.xCoarse+=x;
selStart.y+=y;
selEnd.y+=y;
cursor=selStart;
doPaste(GUI_PASTE_MODE_NORMAL,0,false,c);
@ -2111,4 +2178,4 @@ if (cursorRedoHist.empty()) return;
// apply spot
applyCursorJumpPoint(cursorRedoHist.back());
cursorRedoHist.pop_back();
}
}