Skip to content

Commit

Permalink
Fix multiple editor selection behavior in EditorViewport
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Jan 31, 2024
1 parent 0177e56 commit 24b979b
Showing 1 changed file with 72 additions and 33 deletions.
105 changes: 72 additions & 33 deletions Source/UI/EditorViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EditorViewport::EditorViewport(SignalChainTabComponent* s_)
somethingIsBeingDraggedOver(false),
shiftDown(false),
lastEditorClicked(0),
selectionIndex(0),
selectionIndex(-1),
insertionPoint(0),
componentWantsToMove(false),
indexOfMovingComponent(-1),
Expand Down Expand Up @@ -457,13 +457,48 @@ void EditorViewport::moveSelection(const KeyPress& key)
if (key.getKeyCode() == key.leftKey)
{

if (mk.isShiftDown())
if (mk.isShiftDown()
&& lastEditorClicked != nullptr
&& editorArray.contains(lastEditorClicked))
{
selectionIndex--;
int primaryIndex = editorArray.indexOf(lastEditorClicked);

// set new selection index
if (selectionIndex == -1)
{
// if no selection index has been set yet, set it to the primary index
selectionIndex = primaryIndex == 0 ? 0 : primaryIndex - 1;
}
else if (selectionIndex == 0)
{
// if the selection index is already at the left edge, return
return;
}
else if(selectionIndex <= primaryIndex)
{
// if previous selection index is to the left of the primary index, decrement it
selectionIndex--;
}

// if the editor at the new selection index is empty, skip it
if (editorArray[selectionIndex]->getProcessor()->isEmpty())
{
selectionIndex++;
return;
}

// switch selection state of the editor at the new selection index
if (selectionIndex != primaryIndex)
editorArray[selectionIndex]->switchSelectedState();

// if the selection index is to the right of the primary index,
// decrement it after switching the selection state
if (selectionIndex > primaryIndex)
selectionIndex--;
}
else
{
selectionIndex = 0;
selectionIndex = -1;

for (int i = 0; i < editorArray.size(); i++)
{
Expand All @@ -480,14 +515,41 @@ void EditorViewport::moveSelection(const KeyPress& key)
else if (key.getKeyCode() == key.rightKey)
{

if (mk.isShiftDown())
if (mk.isShiftDown()
&& lastEditorClicked != nullptr
&& editorArray.contains(lastEditorClicked))
{
selectionIndex++;
int primaryIndex = editorArray.indexOf(lastEditorClicked);

if (selectionIndex == -1)
{
// if no selection index has been set yet, set it to the primary index
selectionIndex = primaryIndex == (editorArray.size() - 1) ? primaryIndex : primaryIndex + 1;
}
else if (selectionIndex == editorArray.size() - 1)
{
// if the selection index is already at the right edge, return
return;
}
else if (selectionIndex >= primaryIndex)
{
// if previous selection index is to the right of the primary index, increment it
selectionIndex++;
}

// switch selection state of the editor at the new selection index
if (selectionIndex != primaryIndex)
editorArray[selectionIndex]->switchSelectedState();

// if the selection index is to the left of the primary index,
// increment it after switching the selection state
if (selectionIndex < primaryIndex)
selectionIndex++;
}
else
{

selectionIndex = 0;
selectionIndex = -1;

// bool stopSelection = false;
int i = 0;
Expand All @@ -511,30 +573,6 @@ void EditorViewport::moveSelection(const KeyPress& key)
}
}
}

if (mk.isShiftDown() && lastEditorClicked != 0 && editorArray.contains(lastEditorClicked))
{

LOGDD("Selection index: ", selectionIndex);

int startIndex = editorArray.indexOf(lastEditorClicked);

if (selectionIndex < 0)
{

for (int i = startIndex-1; i >= startIndex + selectionIndex; i--)
{
editorArray[i]->select();
}

} else if (selectionIndex > 0)
{
for (int i = startIndex+1; i <= startIndex + selectionIndex; i++)
{
editorArray[i]->select();
}
}
}
}

bool EditorViewport::keyPressed(const KeyPress& key)
Expand Down Expand Up @@ -635,7 +673,7 @@ void EditorViewport::copySelectedEditors()

for (auto editor : editorArray)
{
if (editor->getSelectionState())
if (!editor->getProcessor()->isEmpty() && editor->getSelectionState())
copyInfo.add( AccessClass::getProcessorGraph()->createNodeXml(editor->getProcessor(), false) );
}

Expand Down Expand Up @@ -938,11 +976,12 @@ void EditorViewport::mouseDown(const MouseEvent& e)
}
}

lastEditorClicked = editorArray[i];
selectionIndex = i;
break;
}

lastEditorClicked = editorArray[i];
selectionIndex = -1;
}
else
{
Expand Down

0 comments on commit 24b979b

Please sign in to comment.