1
+ import { DOCUMENT } from '@angular/common' ;
1
2
import {
2
3
AfterViewInit ,
3
4
ChangeDetectorRef ,
4
5
Component ,
5
6
DestroyRef ,
6
7
EventEmitter ,
8
+ Inject ,
7
9
Input ,
8
10
OnDestroy ,
9
11
Output
@@ -21,6 +23,7 @@ import { fromEvent, Subject, Subscription, timer } from 'rxjs';
21
23
import { takeUntil } from 'rxjs/operators' ;
22
24
import { LocalPresence , Presence } from 'sharedb/lib/sharedb' ;
23
25
import tinyColor from 'tinycolor2' ;
26
+ import { WINDOW } from 'xforge-common/browser-globals' ;
24
27
import { DialogService } from 'xforge-common/dialog.service' ;
25
28
import { LocaleDirection } from 'xforge-common/models/i18n-locale' ;
26
29
import { UserDoc } from 'xforge-common/models/user-doc' ;
@@ -275,7 +278,9 @@ export class TextComponent implements AfterViewInit, OnDestroy {
275
278
private readonly userService : UserService ,
276
279
readonly viewModel : TextViewModel ,
277
280
private readonly textDocService : TextDocService ,
278
- private readonly quillFormatRegistry : QuillFormatRegistryService
281
+ private readonly quillFormatRegistry : QuillFormatRegistryService ,
282
+ @Inject ( DOCUMENT ) private document : Document ,
283
+ @Inject ( WINDOW ) private window : Window
279
284
) {
280
285
let localCursorColor = localStorage . getItem ( this . cursorColorStorageKey ) ;
281
286
if ( localCursorColor == null ) {
@@ -521,19 +526,19 @@ export class TextComponent implements AfterViewInit, OnDestroy {
521
526
522
527
// Listening to document 'selectionchange' event allows local cursor to change position on mousedown,
523
528
// as opposed to quill 'onSelectionChange' event that doesn't fire until mouseup.
524
- fromEvent < MouseEvent > ( document , 'selectionchange' )
529
+ fromEvent < MouseEvent > ( this . document , 'selectionchange' )
525
530
. pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
526
531
. subscribe ( ( ) => {
527
532
this . updateLocalCursor ( ) ;
528
533
} ) ;
529
534
530
- fromEvent < KeyboardEvent > ( document , 'keydown' )
535
+ fromEvent < KeyboardEvent > ( this . document , 'keydown' )
531
536
. pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
532
537
. subscribe ( event => {
533
538
this . isShiftDown = event . shiftKey ;
534
539
} ) ;
535
540
536
- fromEvent < KeyboardEvent > ( document , 'keyup' )
541
+ fromEvent < KeyboardEvent > ( this . document , 'keyup' )
537
542
. pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
538
543
. subscribe ( event => {
539
544
// Call 'update()' when shift key is released, as update is disabled while shift is down
@@ -544,6 +549,18 @@ export class TextComponent implements AfterViewInit, OnDestroy {
544
549
545
550
this . isShiftDown = event . shiftKey ;
546
551
} ) ;
552
+
553
+ fromEvent < FocusEvent > ( this . window , 'blur' )
554
+ . pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
555
+ . subscribe ( ( ) => {
556
+ // Treat window blur as releasing all modifiers
557
+ const wasShiftDown : boolean = this . isShiftDown === true ;
558
+ if ( wasShiftDown ) {
559
+ this . update ( ) ;
560
+ }
561
+
562
+ this . isShiftDown = false ;
563
+ } ) ;
547
564
}
548
565
549
566
ngOnDestroy ( ) : void {
@@ -564,7 +581,7 @@ export class TextComponent implements AfterViewInit, OnDestroy {
564
581
fromEvent ( this . _editor . root , 'scroll' )
565
582
. pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
566
583
. subscribe ( ( ) => this . updateHighlightMarkerVisibility ( ) ) ;
567
- fromEvent ( window , 'resize' )
584
+ fromEvent ( this . window , 'resize' )
568
585
. pipe ( quietTakeUntilDestroyed ( this . destroyRef ) )
569
586
. subscribe ( ( ) => this . setHighlightMarkerPosition ( ) ) ;
570
587
this . viewModel . editor = editor ;
@@ -1144,7 +1161,7 @@ export class TextComponent implements AfterViewInit, OnDestroy {
1144
1161
const cursors : QuillCursors = this . editor . getModule ( 'cursors' ) as QuillCursors ;
1145
1162
cursors . createCursor ( this . presenceId , '' , '' ) ;
1146
1163
1147
- this . localCursorElement = document . querySelector ( `#ql-cursor-${ this . presenceId } ` ) ;
1164
+ this . localCursorElement = this . document . querySelector ( `#ql-cursor-${ this . presenceId } ` ) ;
1148
1165
1149
1166
// Add a specific class to the local cursor
1150
1167
if ( this . localCursorElement != null ) {
@@ -1158,7 +1175,7 @@ export class TextComponent implements AfterViewInit, OnDestroy {
1158
1175
return ;
1159
1176
}
1160
1177
1161
- const sel : Selection | null = window . getSelection ( ) ;
1178
+ const sel : Selection | null = this . window . getSelection ( ) ;
1162
1179
if ( sel == null ) {
1163
1180
return ;
1164
1181
}
0 commit comments