@@ -40,7 +40,7 @@ EditorViewport::EditorViewport(SignalChainTabComponent* s_)
4040 somethingIsBeingDraggedOver(false ),
4141 shiftDown(false ),
4242 lastEditorClicked(0 ),
43- selectionIndex(0 ),
43+ selectionIndex(- 1 ),
4444 insertionPoint(0 ),
4545 componentWantsToMove(false ),
4646 indexOfMovingComponent(-1 ),
@@ -398,13 +398,41 @@ void EditorViewport::moveSelection(const KeyPress& key)
398398 if (key.getKeyCode () == key.leftKey )
399399 {
400400
401- if (mk.isShiftDown ())
401+ if (mk.isShiftDown ()
402+ && lastEditorClicked != 0
403+ && editorArray.contains (lastEditorClicked))
402404 {
403- selectionIndex--;
405+ int primaryIndex = editorArray.indexOf (lastEditorClicked);
406+
407+ // set new selection index
408+ if (selectionIndex == -1 )
409+ {
410+ // if no selection index has been set yet, set it to the primary index
411+ selectionIndex = primaryIndex == 0 ? 0 : primaryIndex - 1 ;
412+ }
413+ else if (selectionIndex == 0 )
414+ {
415+ // if the selection index is already at the left edge, return
416+ return ;
417+ }
418+ else if (selectionIndex <= primaryIndex)
419+ {
420+ // if previous selection index is to the left of the primary index, decrement it
421+ selectionIndex--;
422+ }
423+
424+ // switch selection state of the editor at the new selection index
425+ if (selectionIndex != primaryIndex)
426+ editorArray[selectionIndex]->switchSelectedState ();
427+
428+ // if the selection index is to the right of the primary index,
429+ // decrement it after switching the selection state
430+ if (selectionIndex > primaryIndex)
431+ selectionIndex--;
404432 }
405433 else
406434 {
407- selectionIndex = 0 ;
435+ selectionIndex = - 1 ;
408436
409437 for (int i = 0 ; i < editorArray.size (); i++)
410438 {
@@ -421,14 +449,41 @@ void EditorViewport::moveSelection(const KeyPress& key)
421449 else if (key.getKeyCode () == key.rightKey )
422450 {
423451
424- if (mk.isShiftDown ())
452+ if (mk.isShiftDown ()
453+ && lastEditorClicked != 0
454+ && editorArray.contains (lastEditorClicked))
425455 {
426- selectionIndex++;
456+ int primaryIndex = editorArray.indexOf (lastEditorClicked);
457+
458+ if (selectionIndex == -1 )
459+ {
460+ // if no selection index has been set yet, set it to the primary index
461+ selectionIndex = primaryIndex == (editorArray.size () - 1 ) ? primaryIndex : primaryIndex + 1 ;
462+ }
463+ else if (selectionIndex == editorArray.size () - 1 )
464+ {
465+ // if the selection index is already at the right edge, return
466+ return ;
467+ }
468+ else if (selectionIndex >= primaryIndex)
469+ {
470+ // if previous selection index is to the right of the primary index, increment it
471+ selectionIndex++;
472+ }
473+
474+ // switch selection state of the editor at the new selection index
475+ if (selectionIndex != primaryIndex)
476+ editorArray[selectionIndex]->switchSelectedState ();
477+
478+ // if the selection index is to the left of the primary index,
479+ // increment it after switching the selection state
480+ if (selectionIndex < primaryIndex)
481+ selectionIndex++;
427482 }
428483 else
429484 {
430485
431- selectionIndex = 0 ;
486+ selectionIndex = - 1 ;
432487
433488 // bool stopSelection = false;
434489 int i = 0 ;
@@ -452,30 +507,6 @@ void EditorViewport::moveSelection(const KeyPress& key)
452507 }
453508 }
454509 }
455-
456- if (mk.isShiftDown () && lastEditorClicked != 0 && editorArray.contains (lastEditorClicked))
457- {
458-
459- LOGDD (" Selection index: " , selectionIndex);
460-
461- int startIndex = editorArray.indexOf (lastEditorClicked);
462-
463- if (selectionIndex < 0 )
464- {
465-
466- for (int i = startIndex-1 ; i >= startIndex + selectionIndex; i--)
467- {
468- editorArray[i]->select ();
469- }
470-
471- } else if (selectionIndex > 0 )
472- {
473- for (int i = startIndex+1 ; i <= startIndex + selectionIndex; i++)
474- {
475- editorArray[i]->select ();
476- }
477- }
478- }
479510}
480511
481512bool EditorViewport::keyPressed (const KeyPress& key)
@@ -781,7 +812,6 @@ void EditorViewport::mouseDown(const MouseEvent& e)
781812
782813 m.addItem (6 , " Save image..." , true );
783814
784-
785815 const int result = m.show ();
786816
787817 if (result == 1 )
@@ -894,11 +924,12 @@ void EditorViewport::mouseDown(const MouseEvent& e)
894924 }
895925 }
896926
897- lastEditorClicked = editorArray[i] ;
927+ selectionIndex = i ;
898928 break ;
899929 }
900930
901931 lastEditorClicked = editorArray[i];
932+ selectionIndex = -1 ;
902933 }
903934 else
904935 {
0 commit comments