From adf53472c6e18d0edba888778893244fd53d8425 Mon Sep 17 00:00:00 2001 From: Psycast Date: Wed, 24 Dec 2025 04:15:14 -0330 Subject: [PATCH] Clipboard, String Replace fixes. - Fix some code comments. - Make String replace no longer potentially infinite loop. - Set default ClipboardData values. - Only use notes within a region, not region itself, for minRow. --- src/Core/StringUtils.cpp | 2 +- src/Editor/Clipboard.cpp | 4 ++-- src/Editor/Clipboard.h | 4 ++-- src/Editor/Selection.cpp | 3 +-- src/Managers/NoteMan.cpp | 10 +++++++++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Core/StringUtils.cpp b/src/Core/StringUtils.cpp index c86e2dac..68022c19 100644 --- a/src/Core/StringUtils.cpp +++ b/src/Core/StringUtils.cpp @@ -265,7 +265,7 @@ void Str::replace(std::string& s, const char* fnd, const char* rep) { while (pos != std::string::npos) { s.erase(s.begin() + pos, s.begin() + pos + fndlen); insert(s, pos, rep); - pos = find(s, fnd); + pos = find(s, fnd, pos + replen); } } diff --git a/src/Editor/Clipboard.cpp b/src/Editor/Clipboard.cpp index 87f63496..59d852e8 100644 --- a/src/Editor/Clipboard.cpp +++ b/src/Editor/Clipboard.cpp @@ -93,7 +93,7 @@ void Base64Encode(std::string& out, const uint8_t* in, int size) { uint32_t v = (in[i] << 16) | ((i + 1 < size ? in[i + 1] : 0) << 8) | ((i + 2 < size ? in[i + 2] : 0)); - // Compression - 3 chars -> 1 char + // Compression - 4 chars -> 1 char if (v == 0 && i + 2 < size) { out.push_back('-'); i += 3; @@ -115,7 +115,7 @@ void Base64Decode(Vector& out, const char* in) { int valb = -8; for (const char* p = in; *p; p++) { - // Compression - 1 char -> 3 chars + // Compression - 1 char -> 4 chars if (*p == '-') { out.push_back(0); out.push_back(0); diff --git a/src/Editor/Clipboard.h b/src/Editor/Clipboard.h index ae3ad510..2aa02396 100644 --- a/src/Editor/Clipboard.h +++ b/src/Editor/Clipboard.h @@ -7,8 +7,8 @@ namespace Vortex { struct ClipboardData { - uint8_t version; - uint8_t count; + uint8_t version = 0; + uint8_t count = 0; Vector notes; Vector tempos; }; diff --git a/src/Editor/Selection.cpp b/src/Editor/Selection.cpp index b8f747fe..f0268629 100755 --- a/src/Editor/Selection.cpp +++ b/src/Editor/Selection.cpp @@ -156,8 +156,7 @@ struct SelectionImpl : public Selection { bool timeBased = gView->isTimeBased(); // For this particular case, since this is done via mouse selection, we - // allow notes to be selected - // outside the region + // allow notes to be selected outside the region. if (xl == xr && torT == torB) { double clickY = gView->offsetToY(torT); const ExpandedNote* closest = nullptr; diff --git a/src/Managers/NoteMan.cpp b/src/Managers/NoteMan.cpp index 2bad8520..bf63df24 100755 --- a/src/Managers/NoteMan.cpp +++ b/src/Managers/NoteMan.cpp @@ -691,7 +691,15 @@ struct NotesManImpl : public NotesMan { // Region auto region = gSelection->getSelectedRegion(); - if (!region.isEmpty()) minRow = min(minRow, region.beginRow); + if (!region.isEmpty()) { + for (auto& note : myNotes) { + if (note.row < region.beginRow) continue; + if (note.row > region.endRow) break; + + minRow = min(minRow, note.row); + break; + } + } // Notes for (auto& note : myNotes) {