Update close file logic to select prior if exists; bug fix in LSP regarding editor and assignment

This commit is contained in:
itdominator 2025-07-15 19:46:17 -05:00
parent ae60905eb4
commit d6f766753c
4 changed files with 34 additions and 10 deletions

View File

@ -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);

View File

@ -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);
}
});

View File

@ -42,7 +42,6 @@
<div class="col">
Target Editor: <label [innerText]="editor?.id || '...'"></label>
</div>
<div class="col-sm" [hidden]="!lspManagerService.workspaceFolder">
<button class="btn btn-sm btn-dark"
(click)="registerEditorToLanguageClient()">

View File

@ -37,8 +37,6 @@ export class LspManagerComponent {
activeFile: any;
constructor() {
}
@ -130,8 +128,8 @@ export class LspManagerComponent {
}
private setActiveEditor(message: ServiceMessage) {
this.editor = message.rawData.editor;
this.activeFile = message.rawData.activeFile;
this.editor = message.rawData.editor;
this.activeFile = message.rawData.activeFile;
// TODO: figure out why this doesn't update the session consistently...
// It seems maybe bound to visible state as change detector ref didn't help either.
@ -139,10 +137,11 @@ export class LspManagerComponent {
}
private editorUpdate(message: ServiceMessage) {
if (!this.editor) return;
if (!message.rawData.activeFile) return;
this.editor.setSession(message.rawData.editor.getSession())
this.activeFile = message.rawData.activeFile;
this.activeFile = message.rawData.activeFile;
/*
this.lspManagerService.setSessionFilePath(