Skip to content

Commit

Permalink
[Fix] Pattern tab: Avoid sticky selection key when it's released e.g.…
Browse files Browse the repository at this point in the history
… while a menu is open.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21762 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Sep 26, 2024
1 parent 748d0a7 commit 0dc5a73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions mptrack/View_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ ROWINDEX CViewPattern::SetCurrentRow(ROWINDEX row, WrapMode wrapMode, bool updat
InvalidateRow();

PatternCursor selStart(m_Cursor);
if(m_Status[psKeyboardDragSelect | psMouseDragSelect] && !m_Status[psDragnDropEdit])
if((m_Status[psMouseDragSelect] || IsSelectionPressed()) && !m_Status[psDragnDropEdit])
{
selStart.Set(m_StartSel);
}
Expand All @@ -395,7 +395,7 @@ bool CViewPattern::SetCurrentColumn(CHANNELINDEX channel, PatternCursor::Columns

PatternCursor selStart(m_Cursor);

if(m_Status[psKeyboardDragSelect | psMouseDragSelect] && !m_Status[psDragnDropEdit])
if((m_Status[psMouseDragSelect] || IsSelectionPressed()) && !m_Status[psDragnDropEdit])
{
selStart = m_StartSel;
}
Expand All @@ -419,6 +419,12 @@ void CViewPattern::SetModified(bool updateAllViews)
}


bool CViewPattern::IsSelectionPressed() const
{
return CMainFrame::GetInputHandler()->SelectionPressed();
}


// Fix: If cursor isn't on screen move scrollbars to make it visible
// Fix: save pattern scrollbar position when switching to other tab
// Assume that m_nRow and m_dwCursor are valid
Expand Down Expand Up @@ -782,7 +788,7 @@ void CViewPattern::OnKillFocus(CWnd *pNewWnd)
{
CScrollView::OnKillFocus(pNewWnd);

m_Status.reset(psKeyboardDragSelect | psCtrlDragSelect | psFocussed);
m_Status.reset(psCtrlDragSelect | psFocussed);
InvalidateRow();
}

Expand Down Expand Up @@ -3089,7 +3095,7 @@ void CViewPattern::OnDropSelection()
end.Sanitize(pattern.GetNumRows(), pattern.GetNumChannels());
PatternRect destination(begin, end);

const bool moveSelection = !m_Status[psKeyboardDragSelect | psCtrlDragSelect];
const bool moveSelection = !m_Status[psCtrlDragSelect] && !IsSelectionPressed();

BeginWaitCursor();
pModDoc->GetPatternUndo().PrepareUndo(m_nPattern, 0, 0, sndFile.GetNumChannels(), pattern.GetNumRows(), moveSelection ? "Move Selection" : "Copy Selection");
Expand Down Expand Up @@ -4289,7 +4295,7 @@ void CViewPattern::CursorJump(int distance, bool snap)
row = (((row + (upwards ? -1 : 0)) / distanceAbs) + (upwards ? 0 : 1)) * distanceAbs;
else
row += distance;
row = SetCurrentRow(row, m_Status[psKeyboardDragSelect | psMouseDragSelect] ? WrapMode::LimitAtPatternEnd : WrapMode::WrapAround);
row = SetCurrentRow(row, (m_Status[psMouseDragSelect] || IsSelectionPressed()) ? WrapMode::LimitAtPatternEnd : WrapMode::WrapAround);

if(IsLiveRecord() && !m_Status[psDragActive])
{
Expand Down Expand Up @@ -4576,12 +4582,11 @@ LRESULT CViewPattern::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
case kcSelect:
if(!m_Status[psDragnDropEdit | psRowSelection | psChannelSelection | psMouseDragSelect])
m_StartSel = m_Cursor;
m_Status.set(psKeyboardDragSelect);
return wParam;
case kcSelectOffWithCopySelect:
case kcSelectOffWithNav:
case kcSelectOff:
m_Status.reset(psKeyboardDragSelect | psShiftSelect);
m_Status.reset(psShiftSelect);
return wParam;
case kcCopySelectWithSelect:
case kcCopySelectWithNav:
Expand Down Expand Up @@ -5986,8 +5991,6 @@ void CViewPattern::TempEnterChord(ModCommand::NOTE note)
{
if(m_nSpacing > 0)
{
// Shift from entering chord may have triggered this flag, which will prevent us from wrapping to the next pattern.
m_Status.reset(psKeyboardDragSelect);
SetCurrentRow(GetCurrentRow() + m_nSpacing, (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_CONTSCROLL) ? WrapMode::WrapAround : WrapMode::LimitAtPatternEnd);
}
SetSelToCursor();
Expand Down
3 changes: 2 additions & 1 deletion mptrack/View_pat.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class CViewPattern final : public CModScrollView
enum PatternStatus
{
psMouseDragSelect = 0x01, // Creating a selection using the mouse
psKeyboardDragSelect = 0x02, // Creating a selection using shortcuts
psFocussed = 0x04, // Is the pattern editor focussed
psFollowSong = 0x08, // Does the cursor follow playback
psRecordingEnabled = 0x10, // Recording enabled
Expand Down Expand Up @@ -242,6 +241,8 @@ class CViewPattern final : public CModScrollView

void SetModified(bool updateAllViews = true);

bool IsSelectionPressed() const;

bool UpdateSizes();
void UpdateScrollSize();
void UpdateScrollPos();
Expand Down

0 comments on commit 0dc5a73

Please sign in to comment.