Add editor selection and move keybindings

This commit is contained in:
itdominator 2025-06-13 22:36:01 -05:00
parent 7b498d0602
commit c9c020385d
4 changed files with 143 additions and 7 deletions

View File

@ -13,10 +13,15 @@ export class EditorsService {
private activationSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private switchSessionSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private closeTabSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private selectSessionLeftSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private selectSessionRightSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private moveSessionLeftSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private moveSessionRightSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
constructor() {}
setData(data: ServiceMessage): void {
this.messageSubject.next(data);
}
@ -48,4 +53,37 @@ export class EditorsService {
closeTabRequested$(): Observable<string> {
return this.closeTabSubject.asObservable();
}
moveSessionLeft(data: string): void {
this.moveSessionLeftSubject.next(data);
}
moveSessionLeftRequested$(): Observable<string> {
return this.moveSessionLeftSubject.asObservable();
}
moveSessionRight(data: string): void {
this.moveSessionRightSubject.next(data);
}
moveSessionRightRequested$(): Observable<string> {
return this.moveSessionRightSubject.asObservable();
}
selectSessionLeft(data: string): void {
this.selectSessionLeftSubject.next(data);
}
selectSessionLeftRequested$(): Observable<string> {
return this.selectSessionLeftSubject.asObservable();
}
selectSessionRight(data: string): void {
this.selectSessionRightSubject.next(data);
}
selectSessionRightRequested$(): Observable<string> {
return this.selectSessionRightSubject.asObservable();
}
}

View File

@ -52,14 +52,65 @@ export class EditorsComponent {
this.loadSubscribers();
this.loadMainSubscribers();
let editor = this.createEditor();
this.activeEditor = editor.instance.uuid;
editor.instance.isDefault = true;
let leftEditor = this.createEditor();
let rightEditor = this.createEditor();
this.createEditor();
this.activeEditor = leftEditor.instance.uuid;
leftEditor.instance.isDefault = true;
leftEditor.instance.rightSiblingUUID = rightEditor.instance.uuid;
rightEditor.instance.leftSiblingUUID = leftEditor.instance.uuid;
}
loadSubscribers() {
this.editorsService.selectSessionLeftRequested$().pipe(
takeUntil(this.unsubscribe)
).subscribe((uuid: string) => {
let editorComponent = this.editors.get(uuid).instance;
if (!editorComponent.leftSiblingUUID) return;
let siblingComponent = this.editors.get(editorComponent.leftSiblingUUID).instance;
siblingComponent.editor.focus()
});
this.editorsService.selectSessionRightRequested$().pipe(
takeUntil(this.unsubscribe)
).subscribe((uuid: string) => {
let editorComponent = this.editors.get(uuid).instance;
if (!editorComponent.rightSiblingUUID) return;
let siblingComponent = this.editors.get(editorComponent.rightSiblingUUID).instance;
siblingComponent.editor.focus()
});
this.editorsService.moveSessionLeftRequested$().pipe(
takeUntil(this.unsubscribe)
).subscribe((uuid: string) => {
let editorComponent = this.editors.get(uuid).instance;
if (!editorComponent.leftSiblingUUID) return;
let siblingComponent = this.editors.get(editorComponent.leftSiblingUUID).instance;
let session = editorComponent.editor.getSession();
let siblingSession = siblingComponent.editor.getSession();
if (session == siblingSession) return;
siblingComponent.editor.setSession(session);
editorComponent.newBuffer();
siblingComponent.editor.focus()
});
this.editorsService.moveSessionRightRequested$().pipe(
takeUntil(this.unsubscribe)
).subscribe((uuid: string) => {
let editorComponent = this.editors.get(uuid).instance;
if (!editorComponent.rightSiblingUUID) return;
let siblingComponent = this.editors.get(editorComponent.rightSiblingUUID).instance;
let session = editorComponent.editor.getSession();
let siblingSession = siblingComponent.editor.getSession();
if (session == siblingSession) return;
siblingComponent.editor.setSession(session);
editorComponent.newBuffer();
siblingComponent.editor.focus()
});
this.editorsService.newActiveEditor$().pipe(
takeUntil(this.unsubscribe)
).subscribe((uuid: string) => {
@ -96,6 +147,7 @@ export class EditorsComponent {
this.files.delete(path);
window.fs.closeFile(path);
});
}
loadMainSubscribers() {

View File

@ -12,6 +12,8 @@ export class NewtonEditorBase {
@Input() editorSettings!: typeof EditorSettings;
editor!: any;
uuid!: string;
leftSiblingUUID!: string;
rightSiblingUUID!: string;
cutBuffer: string = "";
timerId: number = -1;
activeFile!: NewtonFile;

View File

@ -56,7 +56,7 @@ export class NewtonEditorComponent extends NewtonEditorBase {
this.editor.commands.addCommands([
{
name: "openCommandPalette2",
bindKey: {linux: "Command-Shift-/|F1", win: "Ctrl-Shift-/|F1"},
bindKey: {linux: "Command-shift-/|F1", win: "ctrl-shift-/|F1"},
exec: () => {
this.commander();
},
@ -68,6 +68,34 @@ export class NewtonEditorComponent extends NewtonEditorBase {
this.search();
},
readOnly: true
}, {
name: "selectSessionLeft",
bindKey: {win: "ctrl-pageup", mac: "ctrl-pageup"},
exec: () => {
this.selectSessionLeft();
},
readOnly: false
}, {
name: "selectSessionRight",
bindKey: {win: "ctrl-pagedown", mac: "ctrl-pagedown"},
exec: () => {
this.selectSessionRight();
},
readOnly: false
}, {
name: "moveSessionLeft",
bindKey: {win: "ctrl-shift-up", mac: "ctrl-shift-up"},
exec: () => {
this.moveSessionLeft();
},
readOnly: false
}, {
name: "moveSessionRight",
bindKey: {win: "ctrl-shift-down", mac: "ctrl-shift-down"},
exec: () => {
this.moveSessionRight();
},
readOnly: false
}, {
name: "movelinesUp",
bindKey: {win: "ctrl-up", mac: "ctrl-up"},
@ -151,8 +179,8 @@ export class NewtonEditorComponent extends NewtonEditorBase {
// Note: https://ajaxorg.github.io/ace-api-docs/interfaces/ace.Ace.EditorEvents.html
this.editor.on("changeStatus", (e) => {
console.log(e);
this.editor.on("focus", (e) => {
this.updateInfoBar();
});
this.editor.on("click", () => {
@ -205,4 +233,20 @@ export class NewtonEditorComponent extends NewtonEditorBase {
this.updateInfoBar();
}
public selectSessionLeft() {
this.editorsService.selectSessionLeft(this.uuid);
}
public selectSessionRight() {
this.editorsService.selectSessionRight(this.uuid);
}
public moveSessionLeft() {
this.editorsService.moveSessionLeft(this.uuid);
}
public moveSessionRight() {
this.editorsService.moveSessionRight(this.uuid);
}
}