Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
verona-modules-aspect
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IQB
verona-modules-aspect
Commits
0a17c1af
Commit
0a17c1af
authored
3 years ago
by
jojohoch
Browse files
Options
Downloads
Patches
Plain Diff
[player] Refactor element overlay component
Break up the code into smaller methods
parent
ec86231c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/player/src/app/components/element-overlay/element-overlay.component.ts
+29
-20
29 additions, 20 deletions
...p/components/element-overlay/element-overlay.component.ts
with
29 additions
and
20 deletions
projects/player/src/app/components/element-overlay/element-overlay.component.ts
+
29
−
20
View file @
0a17c1af
...
@@ -2,12 +2,11 @@ import {
...
@@ -2,12 +2,11 @@ import {
Component
,
OnInit
,
Input
,
ComponentFactoryResolver
,
Component
,
OnInit
,
Input
,
ComponentFactoryResolver
,
ViewChild
,
ViewContainerRef
ViewChild
,
ViewContainerRef
}
from
'
@angular/core
'
;
}
from
'
@angular/core
'
;
import
{
FormBuilder
,
FormGroup
}
from
'
@angular/forms
'
;
import
{
FormGroup
}
from
'
@angular/forms
'
;
import
{
takeUntil
}
from
'
rxjs/operators
'
;
import
{
takeUntil
}
from
'
rxjs/operators
'
;
import
{
Subject
,
Subscription
}
from
'
rxjs
'
;
import
{
Subject
,
Subscription
}
from
'
rxjs
'
;
import
{
UnitUIElement
}
from
'
../../../../../common/unit
'
;
import
{
UnitUIElement
}
from
'
../../../../../common/unit
'
;
import
*
as
ComponentUtils
from
'
../../../../../common/component-utils
'
;
import
*
as
ComponentUtils
from
'
../../../../../common/component-utils
'
;
import
{
FormService
}
from
'
../../../../../common/form.service
'
;
import
{
SpecialCharacterService
}
from
'
../../services/special-character.service
'
;
import
{
SpecialCharacterService
}
from
'
../../services/special-character.service
'
;
import
{
TextFieldComponent
}
from
'
../../../../../common/element-components/text-field.component
'
;
import
{
TextFieldComponent
}
from
'
../../../../../common/element-components/text-field.component
'
;
import
{
TextAreaComponent
}
from
'
../../../../../common/element-components/text-area.component
'
;
import
{
TextAreaComponent
}
from
'
../../../../../common/element-components/text-area.component
'
;
...
@@ -29,9 +28,7 @@ export class ElementOverlayComponent implements OnInit {
...
@@ -29,9 +28,7 @@ export class ElementOverlayComponent implements OnInit {
@
ViewChild
(
'
elementComponentContainer
'
,
@
ViewChild
(
'
elementComponentContainer
'
,
{
read
:
ViewContainerRef
,
static
:
true
})
private
elementComponentContainer
!
:
ViewContainerRef
;
{
read
:
ViewContainerRef
,
static
:
true
})
private
elementComponentContainer
!
:
ViewContainerRef
;
constructor
(
private
formService
:
FormService
,
constructor
(
private
specialCharacterService
:
SpecialCharacterService
,
private
specialCharacterService
:
SpecialCharacterService
,
private
formBuilder
:
FormBuilder
,
private
componentFactoryResolver
:
ComponentFactoryResolver
)
{
private
componentFactoryResolver
:
ComponentFactoryResolver
)
{
}
}
...
@@ -60,29 +57,41 @@ export class ElementOverlayComponent implements OnInit {
...
@@ -60,29 +57,41 @@ export class ElementOverlayComponent implements OnInit {
elementComponent
.
onFocus
elementComponent
.
onFocus
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
subscribe
((
focussedInputControl
:
HTMLElement
):
void
=>
{
.
subscribe
((
focussedInputControl
:
HTMLElement
):
void
=>
{
this
.
specialCharacterService
.
openKeyboard
();
this
.
openKeyboard
(
focussedInputControl
);
this
.
focussedInputSubscription
=
this
.
specialCharacterService
.
characterInput
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
subscribe
((
character
:
string
):
void
=>
{
const
inputElement
=
focussedInputControl
as
HTMLInputElement
;
const
selectionStart
=
inputElement
.
selectionStart
||
0
;
const
selectionEnd
=
inputElement
.
selectionEnd
||
inputElement
.
value
.
length
;
const
startText
=
inputElement
.
value
.
substring
(
0
,
selectionStart
);
const
endText
=
inputElement
.
value
.
substring
(
selectionEnd
);
inputElement
.
value
=
startText
+
character
+
endText
;
const
selection
=
selectionStart
?
selectionStart
+
1
:
1
;
inputElement
.
setSelectionRange
(
selection
,
selection
);
});
});
});
elementComponent
.
onBlur
elementComponent
.
onBlur
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
subscribe
(():
void
=>
{
.
subscribe
(():
void
=>
{
this
.
specialCharacterService
.
closeKeyboard
();
this
.
closeKeyboard
();
this
.
focussedInputSubscription
.
unsubscribe
();
});
});
}
}
private
closeKeyboard
():
void
{
this
.
specialCharacterService
.
closeKeyboard
();
this
.
focussedInputSubscription
.
unsubscribe
();
}
private
openKeyboard
(
focussedInputControl
:
HTMLElement
):
void
{
this
.
specialCharacterService
.
openKeyboard
();
this
.
focussedInputSubscription
=
this
.
specialCharacterService
.
characterInput
.
pipe
(
takeUntil
(
this
.
ngUnsubscribe
))
.
subscribe
((
character
:
string
):
void
=>
{
this
.
onKeyboardInput
(
character
,
focussedInputControl
);
});
}
private
onKeyboardInput
=
(
character
:
string
,
focussedInputControl
:
HTMLElement
):
void
=>
{
const
inputElement
=
focussedInputControl
as
HTMLInputElement
;
const
selectionStart
=
inputElement
.
selectionStart
||
0
;
const
selectionEnd
=
inputElement
.
selectionEnd
||
inputElement
.
value
.
length
;
const
startText
=
inputElement
.
value
.
substring
(
0
,
selectionStart
);
const
endText
=
inputElement
.
value
.
substring
(
selectionEnd
);
inputElement
.
value
=
startText
+
character
+
endText
;
const
selection
=
selectionStart
?
selectionStart
+
1
:
1
;
inputElement
.
setSelectionRange
(
selection
,
selection
);
};
ngOnDestroy
():
void
{
ngOnDestroy
():
void
{
this
.
ngUnsubscribe
.
next
();
this
.
ngUnsubscribe
.
next
();
this
.
ngUnsubscribe
.
complete
();
this
.
ngUnsubscribe
.
complete
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment