diff --git a/src/app/common/services/files.service.ts b/src/app/common/services/files.service.ts index 5375343..32ee31a 100644 --- a/src/app/common/services/files.service.ts +++ b/src/app/common/services/files.service.ts @@ -39,7 +39,23 @@ export class FilesService { return [...this.files.values()]; } - public delete(file: NewtonFile) { + public getPreviousFile(path: string): NewtonFile { + let paths = this.getAllPaths(); + let i = paths.indexOf(path); + + (i == 0) ? i += 1 : i -= 1; + return this.files.get( paths[i] ); + } + + public getNextFile(path: string): NewtonFile { + let paths = this.getAllPaths(); + let i = paths.indexOf(path); + + (i > paths.length) ? i -= 1 : i += 1; + return this.files.get( paths[i] ); + } + + public unset(file: NewtonFile) { file.session.destroy(); window.fs.closeFile(file.path); this.files.delete(file.path); diff --git a/src/app/editor/editors.component.ts b/src/app/editor/editors.component.ts index e1fd93c..1dec7a8 100644 --- a/src/app/editor/editors.component.ts +++ b/src/app/editor/editors.component.ts @@ -131,16 +131,26 @@ export class EditorsComponent { for (let i = 0; i < editors.length; i++) { let editorComponent = editors[i]; - if (editorComponent.editor.session == file.session) { + + if (editorComponent.editor.session !== file.session) continue; + + let targetFile = this.filesService.getPreviousFile(file.path) + if (targetFile) { + editorComponent.assignSession(targetFile); + if (activeComponent == editorComponent) { + this.editorsService.miniMapView.cloneSession(targetFile); + } + } else { + editorComponent.newFile(); if (activeComponent == editorComponent) { this.editorsService.miniMapView.newFile(); } - editorComponent.newFile(); } + } activeComponent.lspManagerService.closeDocument(file.session); - this.filesService.delete(file); + this.filesService.unset(file); } }); diff --git a/src/app/editor/lsp-manager/lsp-manager.component.html b/src/app/editor/lsp-manager/lsp-manager.component.html index 14e5b7d..927792f 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.html +++ b/src/app/editor/lsp-manager/lsp-manager.component.html @@ -42,7 +42,6 @@
Target Editor:
-