From 24a86584c3783b2cc24c10502aab7b2495bb081f Mon Sep 17 00:00:00 2001
From: rhenck <richard.henck@iqb.hu-berlin.de>
Date: Mon, 25 Oct 2021 14:59:39 +0200
Subject: [PATCH] [editor] Fix selected page when deleting sections

Was using the wrong value for determining what page to delete from. Now
correctly uses the SelectionService.
---
 projects/editor/src/app/unit.service.ts | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/projects/editor/src/app/unit.service.ts b/projects/editor/src/app/unit.service.ts
index 57f739190..4acbc498a 100644
--- a/projects/editor/src/app/unit.service.ts
+++ b/projects/editor/src/app/unit.service.ts
@@ -14,6 +14,7 @@ import { TextElement } from '../../../common/models/text-element';
 import { LikertElement } from '../../../common/models/compound-elements/likert-element';
 import { LikertElementRow } from '../../../common/models/compound-elements/likert-element-row';
 import { AnswerOption, LikertRow, PlayerElement } from '../../../common/interfaces/UIElementInterfaces';
+import { SelectionService } from './selection.service';
 
 @Injectable({
   providedIn: 'root'
@@ -24,9 +25,9 @@ export class UnitService {
 
   elementPropertyUpdated: Subject<void> = new Subject<void>();
   pageMoved: Subject<void> = new Subject<void>();
-  selectedPageIndex: number = 0; // TODO weg refactorn
 
-  constructor(private veronaApiService: VeronaAPIService,
+  constructor(private selectionService: SelectionService,
+              private veronaApiService: VeronaAPIService,
               private messageService: MessageService,
               private dialogService: DialogService,
               private sanitizer: DomSanitizer) {
@@ -96,7 +97,7 @@ export class UnitService {
   }
 
   deleteSection(section: Section): void {
-    (this.unitModel.pages[this.selectedPageIndex] as unknown as Page).deleteSection(section as unknown as Section);
+    this.unitModel.pages[this.selectionService.selectedPageIndex].deleteSection(section as unknown as Section);
     this._unit.next(this._unit.value);
     this.veronaApiService.sendVoeDefinitionChangedNotification();
   }
-- 
GitLab