Fix autosave making typed text disappear

This commit is contained in:
Kristóf Tóth 2018-03-02 14:16:55 +01:00
parent c46f5a3458
commit f94a254f9b
2 changed files with 10 additions and 2 deletions

View File

@ -9,7 +9,7 @@
</button> </button>
</div> </div>
<div (keypress)="setButtonStateDirty()" <div (keypress)="setButtonStateDirty(); resetAutoSaveCountdown()"
ace-editor ace-editor
[(text)]="code" [(text)]="code"
[mode]="language" [mode]="language"

View File

@ -34,6 +34,7 @@ export class WebideComponent implements OnInit {
theme = 'monokai'; theme = 'monokai';
files: string[]; files: string[];
saveButtonState = 'SAVED'; saveButtonState = 'SAVED';
autosave = null;
command_handlers = { 'reload': this.reloadHandler.bind(this), command_handlers = { 'reload': this.reloadHandler.bind(this),
'read': this.readHandler.bind(this), 'read': this.readHandler.bind(this),
'select': this.selectHandler.bind(this), 'select': this.selectHandler.bind(this),
@ -49,7 +50,7 @@ export class WebideComponent implements OnInit {
this.requestCode(); this.requestCode();
this.processManagerService.init(); this.processManagerService.init();
this.processManagerService.subscribeCallback('login', (event) => { this.setButtonStateSaved(); }); this.processManagerService.subscribeCallback('login', (event) => { this.setButtonStateSaved(); });
setInterval(() => { this.sendCodeIfDirty(); }, autosave_interval); this.resetAutoSaveCountdown();
} }
subscribeWS() { subscribeWS() {
@ -79,6 +80,13 @@ export class WebideComponent implements OnInit {
this.saveButtonState = 'SAVED'; this.saveButtonState = 'SAVED';
} }
resetAutoSaveCountdown() {
if (this.autosave) {
clearInterval(this.autosave);
}
this.autosave = setInterval(() => { this.sendCodeIfDirty(); }, autosave_interval);
}
tabSwitchButtonHandler(file) { tabSwitchButtonHandler(file) {
if (this.saveButtonState === 'DIRTY') { if (this.saveButtonState === 'DIRTY') {
this.sendCodeContents(); this.sendCodeContents();