Skip to content

Commit f64961f

Browse files
authored
Merge pull request #54 from uvcat7/paste-insert
Add Insert Paste via Shift
2 parents 1a5eecd + 334ced5 commit f64961f

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

src/Editor/Editing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void onKeyPress(KeyPress& evt) override
139139
}
140140
else if(kc == Key::V)
141141
{
142-
pasteFromClipboard();
142+
pasteFromClipboard(evt.keyflags & Keyflag::SHIFT);
143143
evt.handled = true;
144144
}
145145
}
@@ -1034,15 +1034,15 @@ void copySelectionToClipboard(bool remove)
10341034
}
10351035
}
10361036

1037-
void pasteFromClipboard()
1037+
void pasteFromClipboard(bool insert)
10381038
{
10391039
if(gChart->isOpen() && HasClipboardData(NotesMan::clipboardTag))
10401040
{
1041-
gNotes->pasteFromClipboard();
1041+
gNotes->pasteFromClipboard(insert);
10421042
}
10431043
else if(HasClipboardData(TempoMan::clipboardTag))
10441044
{
1045-
gTempo->pasteFromClipboard();
1045+
gTempo->pasteFromClipboard(insert);
10461046
}
10471047
}
10481048

src/Managers/NoteMan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ void copyToClipboard(bool timeBased)
788788
}
789789
}
790790

791-
void pasteFromClipboard()
791+
void pasteFromClipboard(bool insert)
792792
{
793793
Vector<uchar> buffer = GetClipboardData(clipboardTag);
794794
ReadStream stream(buffer.data(), buffer.size());
@@ -822,8 +822,8 @@ void pasteFromClipboard()
822822

823823
// Perform the changes.
824824
static const NotesMan::EditDescription desc = {"Pasted %1 note", "Pasted %1 notes"};
825-
gNotes->modify(edit, true, &desc);
826-
gNotes->select(SELECT_SET, edit.add.begin(), edit.add.size());
825+
modify(edit, !insert, &desc);
826+
select(SELECT_SET, edit.add.begin(), edit.add.size());
827827
}
828828

829829
// ================================================================================================

src/Managers/NoteMan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct NotesMan
5454

5555
// Clipboard functions.
5656
virtual void copyToClipboard(bool timeBased) = 0;
57-
virtual void pasteFromClipboard() = 0;
57+
virtual void pasteFromClipboard(bool insert) = 0;
5858

5959
// Statistics functions.
6060
virtual int getNumSteps() const = 0; ///< Includes jumps/holds/rolls.

src/Managers/TempoMan.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ void myFinishEdit(Tempo* tempo)
143143
// ================================================================================================
144144
// TempoManImpl :: apply segments.
145145

146-
void myQueueSegments(const SegmentEdit& edit)
146+
void myQueueSegments(const SegmentEdit& edit, bool clearRegion)
147147
{
148148
stopTweaking(false);
149149
SegmentEditResult result;
150-
myTempo->segments->prepareEdit(edit, result);
150+
myTempo->segments->prepareEdit(edit, result, clearRegion);
151151
if(result.add.numSegments() + result.rem.numSegments() > 0)
152152
{
153153
WriteStream stream;
@@ -259,7 +259,7 @@ void myWriteInsertRows(WriteStream& stream, Tempo* tempo, int startRow, int numR
259259
}
260260
}
261261
}
262-
segs->prepareEdit(edit, result);
262+
segs->prepareEdit(edit, result, true);
263263
}
264264
stream.write(tempo);
265265
result.rem.encode(stream);
@@ -470,9 +470,14 @@ static double ClampAndRound(double val, double min, double max)
470470
}
471471

472472
void modify(const SegmentEdit& edit)
473+
{
474+
modify(edit, true);
475+
}
476+
477+
void modify(const SegmentEdit& edit, bool clearRegion)
473478
{
474479
stopTweaking(false);
475-
myQueueSegments(edit);
480+
myQueueSegments(edit, clearRegion);
476481
}
477482

478483
void removeSelectedSegments()
@@ -591,7 +596,7 @@ void copyToClipboard()
591596
}
592597
}
593598

594-
void pasteFromClipboard()
599+
void pasteFromClipboard(bool insert)
595600
{
596601
SegmentEdit clipboard;
597602

@@ -616,7 +621,7 @@ void pasteFromClipboard()
616621
}
617622

618623
// Add the pasted segments to the current tempo.
619-
modify(clipboard);
624+
modify(clipboard, !insert);
620625
}
621626

622627
// ================================================================================================

src/Managers/TempoMan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ struct TempoMan
5959

6060
/// Editing functions.
6161
virtual void modify(const SegmentEdit& edit) = 0;
62+
virtual void modify(const SegmentEdit& edit, bool clearRegion) = 0;
6263
virtual void insertRows(int row, int numRows, bool curChartOnly) = 0;
6364
virtual void removeSelectedSegments() = 0;
64-
virtual void pasteFromClipboard() = 0;
65+
virtual void pasteFromClipboard(bool insert) = 0;
6566
virtual void copyToClipboard() = 0;
6667

6768
/// Sets the global music offset.

src/Simfile/SegmentGroup.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,24 @@ void SegmentGroup::sanitize(const Chart* owner)
4545
}
4646
}
4747

48-
void SegmentGroup::prepareEdit(const SegmentEdit& in, SegmentEditResult& out)
48+
void SegmentGroup::prepareEdit(const SegmentEdit& in, SegmentEditResult& out, bool clearRegion)
4949
{
5050
int regionBegin = INT_MAX;
5151
int regionEnd = 0;
52-
ForEachType(type)
52+
if(clearRegion)
5353
{
54-
auto& list = in.add.myLists[type];
55-
if(list.size() >= 2)
54+
ForEachType(type)
5655
{
57-
auto first = list.begin();
58-
auto last = list.rbegin();
59-
if(last->row > first->row)
56+
auto& list = in.add.myLists[type];
57+
if(list.size() >= 2)
6058
{
61-
regionBegin = min(regionBegin, first->row);
62-
regionEnd = max(regionEnd, last->row);
59+
auto first = list.begin();
60+
auto last = list.rbegin();
61+
if(last->row > first->row)
62+
{
63+
regionBegin = min(regionBegin, first->row);
64+
regionEnd = max(regionEnd, last->row);
65+
}
6366
}
6467
}
6568
}

src/Simfile/SegmentGroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SegmentGroup
7777

7878
// Prepares a modification. The input is a list of segments which should be added and removed.
7979
// The output is a list of segments that actually end up being added and removed.
80-
void prepareEdit(const SegmentEdit& in, SegmentEditResult& out);
80+
void prepareEdit(const SegmentEdit& in, SegmentEditResult& out, bool clearRegion);
8181

8282
// Appends a default constructed segment of the given type at the given row.
8383
void append(Segment::Type type, int row);

0 commit comments

Comments
 (0)