From 9acf89b313caa84b30693e32d8c21a11b29c607c Mon Sep 17 00:00:00 2001
From: rhenck <richard.henck@iqb.hu-berlin.de>
Date: Tue, 7 Dec 2021 16:49:02 +0100
Subject: [PATCH] Improve code style

---
 .../page-view/canvas/canvas.component.ts      |  2 +-
 .../canvas/overlays/canvas-element-overlay.ts |  6 ++--
 .../canvas/section-menu.component.ts          |  2 +-
 .../src/app/services/selection.service.ts     |  6 ++--
 .../app/text-editor/font-size-extension.ts    |  2 +-
 .../src/app/text-editor/hanging-indent.ts     |  9 +++---
 projects/editor/src/app/text-editor/indent.ts | 28 +++++++++++--------
 .../app/text-editor/paragraph-extension.ts    |  6 ++--
 8 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts
index 582c60a13..55aba5c29 100644
--- a/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts
+++ b/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts
@@ -121,7 +121,7 @@ export class CanvasComponent implements OnInit, OnDestroy {
   selectElementComponent(element: UIElement): void {
     const elementComponent = this.getElementComponent(element);
     if (elementComponent) {
-      this.selectionService.selectElement({ componentElement: elementComponent, multiSelect: false });
+      this.selectionService.selectElement({ elementComponent: elementComponent, multiSelect: false });
     } else {
       throw Error('Element not found. This is a bug!');
     }
diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts
index d7487eddf..4547062e8 100644
--- a/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts
+++ b/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts
@@ -39,7 +39,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
     // Make children not clickable. This way the only relevant events are managed by the overlay.
     this.childComponent.location.nativeElement.style.pointerEvents = 'none';
 
-    this.selectionService.selectElement({ componentElement: this, multiSelect: false });
+    this.selectionService.selectElement({ elementComponent: this, multiSelect: false });
 
     if (this.childComponent.instance instanceof ClozeComponent) {
       this.childComponent.location.nativeElement.style.pointerEvents = 'unset';
@@ -69,9 +69,9 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
 
   selectElement(multiSelect: boolean = false): void {
     if (multiSelect) {
-      this.selectionService.selectElement({ componentElement: this, multiSelect: true });
+      this.selectionService.selectElement({ elementComponent: this, multiSelect: true });
     } else {
-      this.selectionService.selectElement({ componentElement: this, multiSelect: false });
+      this.selectionService.selectElement({ elementComponent: this, multiSelect: false });
     }
   }
 
diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts
index 942ff09f1..f7774d056 100644
--- a/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts
+++ b/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts
@@ -237,7 +237,7 @@ export class SectionMenuComponent implements OnInit, OnDestroy {
     this.updateGridSizes();
   }
 
-  openColorPicker() {
+  openColorPicker(): void {
     this.colorPicker.nativeElement.click();
   }
 
diff --git a/projects/editor/src/app/services/selection.service.ts b/projects/editor/src/app/services/selection.service.ts
index 803446ee0..6c01eead3 100644
--- a/projects/editor/src/app/services/selection.service.ts
+++ b/projects/editor/src/app/services/selection.service.ts
@@ -24,13 +24,13 @@ export class SelectionService {
     return this._selectedElements.value;
   }
 
-  selectElement(event: { componentElement: any; multiSelect: boolean }): void { // TODO UIElement statt any
+  selectElement(event: { elementComponent: any; multiSelect: boolean }): void {
     if (!event.multiSelect) {
       this.clearElementSelection();
     }
     this.removeCompoundChildSelection();
-    this.selectedElementComponents.push(event.componentElement);
-    event.componentElement.setSelected(true);
+    this.selectedElementComponents.push(event.elementComponent);
+    event.elementComponent.setSelected(true);
     this._selectedElements.next(this.selectedElementComponents.map(componentElement => componentElement.element));
   }
 
diff --git a/projects/editor/src/app/text-editor/font-size-extension.ts b/projects/editor/src/app/text-editor/font-size-extension.ts
index efe67d187..94bcdaeb7 100644
--- a/projects/editor/src/app/text-editor/font-size-extension.ts
+++ b/projects/editor/src/app/text-editor/font-size-extension.ts
@@ -2,7 +2,7 @@ import { Command } from '@tiptap/core';
 import { TextStyle } from '@tiptap/extension-text-style';
 
 declare module '@tiptap/core' {
-  interface Commands<ReturnType> {
+  interface Commands<> {
     fontSizeExtension: {
       setFontSize: (fontSize: string) => Command
     };
diff --git a/projects/editor/src/app/text-editor/hanging-indent.ts b/projects/editor/src/app/text-editor/hanging-indent.ts
index 71eb3b7e6..428922d58 100644
--- a/projects/editor/src/app/text-editor/hanging-indent.ts
+++ b/projects/editor/src/app/text-editor/hanging-indent.ts
@@ -68,11 +68,12 @@ export const HangingIndent = Extension.create({
     const applyIndent: (hangingIndent: boolean, indentSize: number) => () => Command =
       (hangingIndent, indentSize) => () => ({ tr, state, dispatch }) => {
         const { selection } = state;
-        tr = tr.setSelection(selection);
-        tr = updateIndentLevel(tr, hangingIndent, indentSize);
+        let transaction;
+        transaction = tr.setSelection(selection);
+        transaction = updateIndentLevel(transaction, hangingIndent, indentSize);
 
-        if (tr.docChanged) {
-          dispatch?.(tr);
+        if (transaction.docChanged) {
+          dispatch?.(transaction);
           return true;
         }
 
diff --git a/projects/editor/src/app/text-editor/indent.ts b/projects/editor/src/app/text-editor/indent.ts
index 7bdc5385c..6d2e19676 100644
--- a/projects/editor/src/app/text-editor/indent.ts
+++ b/projects/editor/src/app/text-editor/indent.ts
@@ -1,5 +1,5 @@
 import { Command, Extension } from '@tiptap/core';
-import { TextSelection, AllSelection, Transaction } from 'prosemirror-state';
+import { TextSelection, Transaction } from 'prosemirror-state';
 
 export interface IndentOptions {
   types: string[];
@@ -56,7 +56,12 @@ export const Indent = Extension.create<IndentOptions>({
       if (node) {
         const nextLevel = (node.attrs.indent || 0) + delta;
         const { minLevel, maxLevel } = this.options;
-        const indent = nextLevel < minLevel ? minLevel : nextLevel > maxLevel ? maxLevel : nextLevel;
+        let indent: number;
+        if (nextLevel < minLevel) {
+          indent = minLevel;
+        } else {
+          indent = nextLevel > maxLevel ? maxLevel : nextLevel;
+        }
 
         if (indent !== node.attrs.indent) {
           const nodeAttrs = { ...node.attrs, indent, indentSize };
@@ -68,29 +73,30 @@ export const Indent = Extension.create<IndentOptions>({
 
     const updateIndentLevel = (tr: Transaction, delta: number, indentSize: number): Transaction => {
       const { doc, selection } = tr;
+      let transaction = tr;
 
-      if (doc && selection && (selection instanceof TextSelection || selection instanceof AllSelection)) {
+      if (doc && selection && (selection instanceof TextSelection)) {
         const { from, to } = selection;
         doc.nodesBetween(from, to, (node, pos) => {
           if (this.options.types.includes(node.type.name)) {
-            tr = setNodeIndentMarkup(tr, pos, delta, indentSize);
+            transaction = setNodeIndentMarkup(tr, pos, delta, indentSize);
             return false;
           }
-
           return true;
         });
       }
-
-      return tr;
+      return transaction;
     };
+
     const applyIndent: (direction: number, indentSize: number) => () => Command =
       (direction, indentSize) => () => ({ tr, state, dispatch }) => {
         const { selection } = state;
-        tr = tr.setSelection(selection);
-        tr = updateIndentLevel(tr, direction, indentSize);
+        let transaction;
+        transaction = tr.setSelection(selection);
+        transaction = updateIndentLevel(transaction, direction, indentSize);
 
-        if (tr.docChanged) {
-          dispatch?.(tr);
+        if (transaction.docChanged) {
+          dispatch?.(transaction);
           return true;
         }
 
diff --git a/projects/editor/src/app/text-editor/paragraph-extension.ts b/projects/editor/src/app/text-editor/paragraph-extension.ts
index c7735e272..52415f312 100644
--- a/projects/editor/src/app/text-editor/paragraph-extension.ts
+++ b/projects/editor/src/app/text-editor/paragraph-extension.ts
@@ -4,7 +4,7 @@ import { Transaction } from 'prosemirror-state';
 
 declare module '@tiptap/core' {
   interface Commands<ReturnType> {
-    setMargin: { // TODO customParagraph: { ?
+    setMargin: {
       setMargin: (newMargin: number) => ReturnType;
     };
   }
@@ -15,9 +15,7 @@ export const customParagraph = Paragraph.extend({
     return {
       margin: {
         default: 10,
-        parseHTML: element => {
-          return Number(element.style.marginBottom.slice(0, -2));
-        },
+        parseHTML: element => Number(element.style.marginBottom.slice(0, -2)),
         renderHTML: attributes => ({
           style: `margin-bottom: ${attributes.margin}px; margin-top: 0`
         })
-- 
GitLab