Editor Service
The Editor Service (IEditorService) is a workbench service that manages opening, closing, and interacting with editors across editor groups. It provides a high-level API for editor operations and tracks the active and visible editors.
Service Overview
The Editor Service is defined insrc/vs/workbench/services/editor/common/editorService.ts:17 and serves as the primary interface for editor management.
Service Identifier
Dependency Injection
Opening Editors
openEditor() - Open Single Editor
IUntypedEditorInput
required
The editor input to open (resource, options, etc.)
PreferredGroup
Target group:
ACTIVE_GROUP, SIDE_GROUP, AUX_WINDOW_GROUP, or group identifierGroup Constants
Group Constants
Opening Different Editor Types
Text Files
Text Files
Diff Editors
Diff Editors
Untitled Files
Untitled Files
openEditors() - Open Multiple Editors
Managing Editors
Active and Visible Editors
Finding Editors
Closing Editors
Replacing Editors
Saving and Reverting
Saving Editors
Reverting Editors
Editor Enumeration
Events
onDidActiveEditorChange
onDidVisibleEditorsChange
onDidEditorsChange
onWillOpenEditor
onDidCloseEditor
Common Use Cases
Opening Files with Selection
Managing Editor Layout
Tracking Active Editor
Smart Save Operations
Best Practices
Use Untyped Inputs: Prefer untyped editor inputs (
{ resource: uri }) over creating EditorInput instances. This allows the editor resolver to select the appropriate editor.Preserve Focus: When opening editors in the background, use
preserveFocus: true to keep the user’s current focus.Handle Missing Files: Always handle cases where files might not exist or fail to open. Check
isOpened() before performing operations.Group Management: Use
SIDE_GROUP to open editors to the side, but consider using IEditorGroupsService for more complex layout requirements.Event Disposal: Always dispose of event listeners when your component is disposed to prevent memory leaks.
Related Services
- IEditorGroupsService - Lower-level service for managing editor groups
- IEditorResolverService - Maps resources to appropriate editor types
- ITextFileService - Higher-level service for text file operations