-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set active editor on startup #6152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ | |
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Event, Emitter } from '@theia/core'; | ||
import { Emitter, Event } from '@theia/core'; | ||
import { EditorManager, EditorWidget } from '@theia/editor/lib/browser'; | ||
import { injectable, inject } from 'inversify'; | ||
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; | ||
import { inject, injectable } from 'inversify'; | ||
|
||
export const TextEditorService = Symbol('TextEditorService'); | ||
/** | ||
|
@@ -38,25 +38,19 @@ export class TextEditorServiceImpl implements TextEditorService { | |
onTextEditorAdd: Event<MonacoEditor> = this.onTextEditorAddEmitter.event; | ||
onTextEditorRemove: Event<MonacoEditor> = this.onTextEditorRemoveEmitter.event; | ||
|
||
private editors = new Map<string, MonacoEditor>(); | ||
|
||
constructor(@inject(EditorManager) private editorManager: EditorManager) { | ||
editorManager.onCurrentEditorChanged(this.onEditorChanged); | ||
editorManager.onCreated(w => this.onEditorCreated(w)); | ||
editorManager.all.forEach(w => this.onEditorCreated(w)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tolusha thanks for tackling this! 🙏 in general this should work, but we could actually clean up the WDYT of renaming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a bit off topic as this is not related to the issue in scope of this PR, but before I forget to mention it: I think we should remove e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AlexTugarev There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok with me. let's test with many opened editors to see how it works with many events being fired. |
||
} | ||
|
||
listTextEditors(): MonacoEditor[] { | ||
return Array.from(this.editors.values()); | ||
return this.editorManager.all.map(w => MonacoEditor.get(w)!).filter(editor => editor !== undefined); | ||
} | ||
|
||
getActiveEditor(): EditorWidget | undefined { | ||
return this.editorManager.activeEditor; | ||
} | ||
|
||
private onEditorChanged(editor: EditorWidget | undefined): void { | ||
// console.log(`Current Editor Changed: ${editor}`); | ||
} | ||
|
||
private onEditorCreated(editor: EditorWidget): void { | ||
const monacoEditor = MonacoEditor.get(editor); | ||
if (monacoEditor) { | ||
|
@@ -66,16 +60,10 @@ export class TextEditorServiceImpl implements TextEditorService { | |
} | ||
|
||
private onEditorAdded(editor: MonacoEditor): void { | ||
if (!this.editors.has(editor.getControl().getId())) { | ||
this.editors.set(editor.getControl().getId(), editor); | ||
this.onTextEditorAddEmitter.fire(editor); | ||
} | ||
this.onTextEditorAddEmitter.fire(editor); | ||
} | ||
|
||
private onEditorRemoved(editor: MonacoEditor): void { | ||
if (this.editors.has(editor.getControl().getId())) { | ||
this.editors.delete(editor.getControl().getId()); | ||
this.onTextEditorRemoveEmitter.fire(editor); | ||
} | ||
this.onTextEditorRemoveEmitter.fire(editor); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always nice to remove duplicate state! 😊