11import { Component , ElementRef , OnInit , ViewChild } from '@angular/core' ;
2- import { el } from "@angular/platform-browser/testing/src/browser_util" ;
32import { applyUpdate , Document } from "../model/document" ;
43import { createUpdate , Update } from "../model/update" ;
54import { DocumentService } from "../services/document.service" ;
@@ -15,7 +14,7 @@ export class DocumentComponent implements OnInit {
1514 currentDocument : Document ;
1615 newDocument : Document ;
1716 newName : string ;
18- updateSubject :WebSocketSubject < Update > ;
17+ updateSubject : WebSocketSubject < Update > ;
1918 private textArea : ElementRef ;
2019 selectionStart : number ;
2120 selectionEnd : number ;
@@ -31,7 +30,7 @@ export class DocumentComponent implements OnInit {
3130 this . newName = "" ;
3231 }
3332
34- updateCurrentDocument ( update : Update ) {
33+ updateCurrentDocument ( update : Update ) {
3534 this . updateSubject . send ( update )
3635 }
3736
@@ -40,7 +39,7 @@ export class DocumentComponent implements OnInit {
4039 this . documents = docs ;
4140 if ( docs . length > 0 ) {
4241 this . currentDocument = docs [ 0 ] ;
43- this . currentDocument . previousContent = this . currentDocument . content ;
42+ this . currentDocument . previousContent = this . currentDocument . content ;
4443 this . documentSelected ( this . currentDocument )
4544 }
4645 }
@@ -72,20 +71,20 @@ export class DocumentComponent implements OnInit {
7271 )
7372 }
7473
75- documentSelected ( document : Document ) {
76- if ( this . updateSubject ) {
74+ documentSelected ( document : Document ) {
75+ if ( this . updateSubject ) {
7776 this . updateSubject . complete ( )
7877 }
79- this . documentService . getWsConnection ( document . name ) . subscribe ( ( ws :WebSocketSubject < Update > ) => {
78+ this . documentService . getWsConnection ( document . name ) . subscribe ( ( ws : WebSocketSubject < Update > ) => {
8079 this . updateSubject = ws ;
81- this . updateSubject . subscribe ( ( update : Update ) => {
82- applyUpdate ( document , update )
80+ this . updateSubject . subscribe ( ( update : Update ) => {
81+ applyUpdate ( document , update )
8382 } )
8483 } ) ;
8584 }
8685
8786 isRenamingDisabled ( ) {
88- return this . newName . length === 0 ;
87+ return this . newName . length === 0 ;
8988 }
9089
9190 @ViewChild ( "textArea" )
@@ -96,28 +95,28 @@ export class DocumentComponent implements OnInit {
9695
9796 textChanged ( event , document : Document ) {
9897
99- let update :Update ;
98+ let update : Update ;
10099
101- if ( event . inputType === "deleteContentBackward" ) {
102- if ( this . selectionStart === this . selectionEnd ) {
103- update = createUpdate ( "" , this . selectionStart - 1 , this . selectionEnd , false )
100+ if ( event . inputType === "deleteContentBackward" ) {
101+ if ( this . selectionStart === this . selectionEnd ) {
102+ update = createUpdate ( "" , this . selectionStart - 1 , this . selectionEnd , false )
104103 } else {
105- update = createUpdate ( "" , this . selectionStart , this . selectionEnd , false )
104+ update = createUpdate ( "" , this . selectionStart , this . selectionEnd , false )
106105 }
107- } else if ( event . inputType === "deleteContentForward" ) {
108- update = createUpdate ( "" , this . selectionStart , this . selectionEnd + 1 , false )
106+ } else if ( event . inputType === "deleteContentForward" ) {
107+ update = createUpdate ( "" , this . selectionStart , this . selectionEnd + 1 , false )
108+ } else if ( event . inputType === "insertLineBreak" ) {
109+ update = createUpdate ( "\n" , this . selectionStart , this . selectionEnd , false )
109110 } else {
110- const appending : boolean = this . selectionStart === this . selectionEnd && document . content . length === this . selectionEnd + 1 ;
111- update = createUpdate ( document . content . substring ( this . selectionStart , this . selectionEnd + 1 ) , this . selectionStart , this . selectionEnd , appending )
111+ const appending : boolean = this . selectionStart === this . selectionEnd && document . content . length === this . selectionEnd + 1 ;
112+ update = createUpdate ( document . content . substring ( this . selectionStart , this . selectionEnd + 1 ) , this . selectionStart , this . selectionEnd , appending )
112113 }
113114
114115 this . updateCurrentDocument ( update )
115116 }
116117
117118 updateSelection ( ) {
118- this . selectionStart = this . textArea . nativeElement . selectionStart ;
119- this . selectionEnd = this . textArea . nativeElement . selectionEnd ;
120- console . log ( this . selectionStart ) ;
121- console . log ( this . selectionEnd ) ;
119+ this . selectionStart = this . textArea . nativeElement . selectionStart ;
120+ this . selectionEnd = this . textArea . nativeElement . selectionEnd ;
122121 }
123122}
0 commit comments