diff --git a/Source/UI/EditorViewport.cpp b/Source/UI/EditorViewport.cpp index 9b7b62ada..870eb8cc4 100755 --- a/Source/UI/EditorViewport.cpp +++ b/Source/UI/EditorViewport.cpp @@ -40,7 +40,7 @@ EditorViewport::EditorViewport(SignalChainTabComponent* s_) somethingIsBeingDraggedOver(false), shiftDown(false), lastEditorClicked(0), - selectionIndex(0), + selectionIndex(-1), insertionPoint(0), componentWantsToMove(false), indexOfMovingComponent(-1), @@ -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++) { @@ -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; @@ -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) @@ -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) ); } @@ -938,11 +976,12 @@ void EditorViewport::mouseDown(const MouseEvent& e) } } - lastEditorClicked = editorArray[i]; + selectionIndex = i; break; } lastEditorClicked = editorArray[i]; + selectionIndex = -1; } else {