Multi-Instance Patterns
Running several editors on one screen is a primary Editora use case and requires explicit isolation patterns.
Instance isolation rules
- Each editor must own its toolbar, dialogs, sidebars, and statusbar updates.
- Selection state must be captured/restored per instance.
- Commands must execute against active instance only.
UI surface scoping
- Mount comments/spellcheck sidebars to the local editor container.
- Position inline dialogs relative to the clicked toolbar control in the same instance.
- Prevent close/open handlers from toggling sibling editor overlays.
Common failure patterns to avoid
- Global
document.querySelector(...)resolving first/last matching editor. - Shared singleton state for selection, panel visibility, or toolbar context.
- Cross-instance event handlers not filtered by editor root.
Recommended architecture
- Keep an editor-local runtime context object.
- Register listeners through the instance lifecycle.
- Remove listeners and mounted overlays on destroy.
- Use editor root references for all DOM queries.
API Surface
- Instance-scoped command registry.
- Editor root references for plugin UI mount points.
- Lifecycle hooks (
onInit,onDestroy) for cleanup.
Config Matrix
| Concern | Configuration/Pattern | Outcome |
|---|---|---|
| Panel mounting | local host container refs | no cross-instance leakage |
| Command routing | active-editor context | correct target execution |
| Theme scope | per-editor class/attribute | mixed-theme support |
| Teardown | lifecycle cleanup hooks | no dangling listeners |
Validation Checklist
- Opening/closing a panel in editor A never toggles editor B.
- Selection-based commands apply only to the active editor.
- Statusbar counters update only for the editor being edited.
- Destroying one instance leaves other instances fully operational.