Skip to content
Snippets Groups Projects
Commit fd034758 authored by jojohoch's avatar jojohoch
Browse files

[player] Refactor applySelection parameter

- Remove element as parameter
parent 12662c72
No related branches found
No related tags found
No related merge requests found
...@@ -36,13 +36,11 @@ import { TextElement } from '../../ui-elements/text/text-element'; ...@@ -36,13 +36,11 @@ import { TextElement } from '../../ui-elements/text/text-element';
] ]
}) })
export class MarkingBarComponent { export class MarkingBarComponent {
@Input() element!: HTMLElement;
@Input() elementModel!: TextElement; @Input() elementModel!: TextElement;
@Output() applySelection = new EventEmitter<{ @Output() applySelection = new EventEmitter<{
active: boolean, active: boolean,
mode: 'mark' | 'delete', mode: 'mark' | 'delete',
color: string, color: string
element: HTMLElement
}>(); }>();
selectedColor!: string; selectedColor!: string;
...@@ -51,7 +49,7 @@ export class MarkingBarComponent { ...@@ -51,7 +49,7 @@ export class MarkingBarComponent {
this.selectedColor = selection.selected ? selection.color : 'none'; this.selectedColor = selection.selected ? selection.color : 'none';
this.applySelection this.applySelection
.emit({ .emit({
active: selection.selected, mode: selection.mode, color: selection.color, element: this.element active: selection.selected, mode: selection.mode, color: selection.color
}); });
} }
} }
...@@ -16,11 +16,10 @@ import { ValueChangeElement } from '../../models/uI-element'; ...@@ -16,11 +16,10 @@ import { ValueChangeElement } from '../../models/uI-element';
*ngIf="elementModel.highlightableYellow || *ngIf="elementModel.highlightableYellow ||
elementModel.highlightableTurquoise || elementModel.highlightableTurquoise ||
elementModel.highlightableOrange" elementModel.highlightableOrange"
[element]="container"
[elementModel]="elementModel" [elementModel]="elementModel"
(applySelection)="applySelection.emit($event)"> (applySelection)="applySelection.emit($event)">
</app-marking-bar> </app-marking-bar>
<div #container class="text-container" <div #textContainerRef class="text-container"
[style.background-color]="elementModel.surfaceProps.backgroundColor" [style.background-color]="elementModel.surfaceProps.backgroundColor"
[style.color]="elementModel.fontProps.fontColor" [style.color]="elementModel.fontProps.fontColor"
[style.font-family]="elementModel.fontProps.font" [style.font-family]="elementModel.fontProps.font"
...@@ -51,9 +50,8 @@ export class TextComponent extends ElementComponent { ...@@ -51,9 +50,8 @@ export class TextComponent extends ElementComponent {
@Output() applySelection = new EventEmitter<{ @Output() applySelection = new EventEmitter<{
active: boolean, active: boolean,
mode: 'mark' | 'delete', mode: 'mark' | 'delete',
color: string, color: string
element: HTMLElement
}>(); }>();
@ViewChild('container') containerDiv!: ElementRef; @ViewChild('textContainerRef') textContainerRef!: ElementRef;
} }
...@@ -193,8 +193,8 @@ export class ElementContainerComponent implements OnInit { ...@@ -193,8 +193,8 @@ export class ElementContainerComponent implements OnInit {
private stopSelection(mouseEvent: MouseEvent, elementComponent: TextComponent) { private stopSelection(mouseEvent: MouseEvent, elementComponent: TextComponent) {
const selection = window.getSelection(); const selection = window.getSelection();
if (selection) { if (selection) {
if (!this.markingService.isDescendantOf(selection.anchorNode, elementComponent.containerDiv.nativeElement) || if (!this.markingService.isDescendantOf(selection.anchorNode, elementComponent.textContainerRef.nativeElement) ||
!this.markingService.isDescendantOf(selection.focusNode, elementComponent.containerDiv.nativeElement) || !this.markingService.isDescendantOf(selection.focusNode, elementComponent.textContainerRef.nativeElement) ||
(mouseEvent.ctrlKey && selection.rangeCount)) { (mouseEvent.ctrlKey && selection.rangeCount)) {
selection.removeAllRanges(); selection.removeAllRanges();
} else if (this.selectedMode && this.selectedColor) { } else if (this.selectedMode && this.selectedColor) {
...@@ -202,7 +202,7 @@ export class ElementContainerComponent implements OnInit { ...@@ -202,7 +202,7 @@ export class ElementContainerComponent implements OnInit {
.applySelection( .applySelection(
this.selectedMode, this.selectedMode,
this.selectedColor, this.selectedColor,
elementComponent.containerDiv.nativeElement, elementComponent.textContainerRef.nativeElement,
elementComponent as TextComponent elementComponent as TextComponent
); );
} }
...@@ -218,13 +218,15 @@ export class ElementContainerComponent implements OnInit { ...@@ -218,13 +218,15 @@ export class ElementContainerComponent implements OnInit {
active: boolean, active: boolean,
mode: 'mark' | 'delete', mode: 'mark' | 'delete',
color: string; color: string;
element: HTMLElement;
}) => { }) => {
if (selection.active) { if (selection.active) {
this.selectedColor = selection.color; this.selectedColor = selection.color;
this.selectedMode = selection.mode; this.selectedMode = selection.mode;
this.markingService this.markingService
.applySelection(selection.mode, selection.color, selection.element, elementComponent as TextComponent); .applySelection(selection.mode,
selection.color,
elementComponent.textContainerRef.nativeElement,
elementComponent as TextComponent);
} else { } else {
this.selectedColor = null; this.selectedColor = null;
this.selectedMode = null; this.selectedMode = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment