Skip to content

Commit 0c74510

Browse files
committed
refactored
1 parent a9e65ae commit 0c74510

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

webclient/src/main/web/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webclient/src/main/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@angular/platform-browser-dynamic": "~7.2.0",
2222
"@angular/router": "~7.2.0",
2323
"@types/dom-inputevent": "^1.0.4",
24+
"bootstrap": "^4.3.1",
2425
"core-js": "^2.5.4",
2526
"net": "^1.0.2",
2627
"rxjs": "~6.3.3",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

webclient/src/main/web/src/app/document/document.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<button (click)="addNewDocument(newDocument)">Add</button>
1313
</div>
1414
<hr>
15-
<div>
16-
<label *ngIf="currentDocument"> {{currentDocument.name}}:<br>
15+
<div *ngIf="currentDocument">
16+
<label> {{currentDocument.name}}:<br>
1717
<textarea appBlockPaste #textArea [(ngModel)]="currentDocument.content"
1818
(input)="textChanged($event ,currentDocument)"
1919
(mousedown)="updateSelection()"

webclient/src/main/web/src/app/document/document.component.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
2-
import {applyUpdate, Document} from "../model/document";
2+
import {Document} from "../model/document";
33
import {createUpdate, Update} from "../model/update";
44
import {DocumentService} from "../services/document.service";
55
import {WebSocketSubject} from "../services/webSocketSubject";
@@ -47,6 +47,8 @@ export class DocumentComponent implements OnInit {
4747
this.currentDocument = docs[0];
4848
this.currentDocument.previousContent = this.currentDocument.content;
4949
this.documentSelected(this.currentDocument)
50+
} else {
51+
this.currentDocument = null;
5052
}
5153
}
5254
)
@@ -84,7 +86,7 @@ export class DocumentComponent implements OnInit {
8486
this.documentService.getWsConnection(document.name).subscribe((ws: WebSocketSubject<Update>) => {
8587
this.updateSubject = ws;
8688
this.updateSubject.subscribe((update: Update) => {
87-
applyUpdate(document, update)
89+
this.applyUpdate(document, update);
8890
})
8991
});
9092
}
@@ -105,8 +107,8 @@ export class DocumentComponent implements OnInit {
105107
}
106108
} else if (event.inputType === "deleteContentForward") {
107109
update = createUpdate("", this.selectionStart, this.selectionEnd + 1, false)
108-
} else if (event.inputType==="insertLineBreak") {
109-
update = createUpdate("\n",this.selectionStart,this.selectionEnd,false)
110+
} else if (event.inputType === "insertLineBreak") {
111+
update = createUpdate("\n", this.selectionStart, this.selectionEnd, false)
110112
} else {
111113
const appending: boolean = this.selectionStart === this.selectionEnd && document.content.length === this.selectionEnd + 1;
112114
update = createUpdate(document.content.substring(this.selectionStart, this.selectionEnd + 1), this.selectionStart, this.selectionEnd, appending)
@@ -119,4 +121,22 @@ export class DocumentComponent implements OnInit {
119121
this.selectionStart = this.textArea.nativeElement.selectionStart;
120122
this.selectionEnd = this.textArea.nativeElement.selectionEnd;
121123
}
124+
125+
applyUpdate(document: Document, update: Update) {
126+
const start = this.textArea.nativeElement.selectionStart;
127+
const end = this.textArea.nativeElement.selectionEnd;
128+
const oldContent: String = document.content;
129+
130+
if (update.appending) {
131+
document.previousContent = document.previousContent + update.content
132+
} else {
133+
const first = document.previousContent.substring(0, update.start);
134+
const last = document.previousContent.substring(update.end);
135+
136+
document.previousContent = first + update.content + last
137+
}
138+
if (document.content !== document.previousContent) {
139+
document.content = document.previousContent;
140+
}
141+
}
122142
}

webclient/src/main/web/src/app/model/document.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,3 @@ export class Document {
1111
this.previousContent = content;
1212
}
1313
}
14-
15-
16-
17-
export function applyUpdate(document: Document ,update: Update){
18-
if(update.appending){
19-
document.previousContent = document.previousContent+update.content
20-
} else {
21-
const first = document.previousContent.substring(0, update.start);
22-
const last = document.previousContent.substring(update.end);
23-
24-
document.previousContent = first+update.content+ last
25-
}
26-
if(document.content !== document.previousContent){
27-
document.content = document.previousContent
28-
}
29-
}

0 commit comments

Comments
 (0)