Skip to main content

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 in src/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 identifier

Opening Different Editor Types

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.
  • IEditorGroupsService - Lower-level service for managing editor groups
  • IEditorResolverService - Maps resources to appropriate editor types
  • ITextFileService - Higher-level service for text file operations

See Also