diff --git a/src/app/common/services/editor/editors.service.ts b/src/app/common/services/editor/editors.service.ts index 9da6853..84e9af9 100644 --- a/src/app/common/services/editor/editors.service.ts +++ b/src/app/common/services/editor/editors.service.ts @@ -13,10 +13,15 @@ export class EditorsService { private activationSubject: ReplaySubject = new ReplaySubject(1); private switchSessionSubject: ReplaySubject = new ReplaySubject(1); private closeTabSubject: ReplaySubject = new ReplaySubject(1); + private selectSessionLeftSubject: ReplaySubject = new ReplaySubject(1); + private selectSessionRightSubject: ReplaySubject = new ReplaySubject(1); + private moveSessionLeftSubject: ReplaySubject = new ReplaySubject(1); + private moveSessionRightSubject: ReplaySubject = new ReplaySubject(1); constructor() {} + setData(data: ServiceMessage): void { this.messageSubject.next(data); } @@ -48,4 +53,37 @@ export class EditorsService { closeTabRequested$(): Observable { return this.closeTabSubject.asObservable(); } + + moveSessionLeft(data: string): void { + this.moveSessionLeftSubject.next(data); + } + + moveSessionLeftRequested$(): Observable { + return this.moveSessionLeftSubject.asObservable(); + } + + moveSessionRight(data: string): void { + this.moveSessionRightSubject.next(data); + } + + moveSessionRightRequested$(): Observable { + return this.moveSessionRightSubject.asObservable(); + } + + selectSessionLeft(data: string): void { + this.selectSessionLeftSubject.next(data); + } + + selectSessionLeftRequested$(): Observable { + return this.selectSessionLeftSubject.asObservable(); + } + + selectSessionRight(data: string): void { + this.selectSessionRightSubject.next(data); + } + + selectSessionRightRequested$(): Observable { + return this.selectSessionRightSubject.asObservable(); + } + } \ No newline at end of file diff --git a/src/app/editor/editors.component.ts b/src/app/editor/editors.component.ts index c4c080b..80777d7 100644 --- a/src/app/editor/editors.component.ts +++ b/src/app/editor/editors.component.ts @@ -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() { diff --git a/src/app/editor/newton-editor/newton-editor.base.ts b/src/app/editor/newton-editor/newton-editor.base.ts index 893b9c0..f2b0950 100644 --- a/src/app/editor/newton-editor/newton-editor.base.ts +++ b/src/app/editor/newton-editor/newton-editor.base.ts @@ -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; diff --git a/src/app/editor/newton-editor/newton-editor.component.ts b/src/app/editor/newton-editor/newton-editor.component.ts index 69ad9d9..6dec869 100644 --- a/src/app/editor/newton-editor/newton-editor.component.ts +++ b/src/app/editor/newton-editor/newton-editor.component.ts @@ -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); + } + } \ No newline at end of file