# Editors class
{: .no_toc }

The collection of editors active in the IDE --- accessible through [**Host.ActiveEditors**](/tB/Packages/tbIDE/Host.md#activeeditors). The IDE currently exposes exactly one active editor at a time, but the collection interface allows future versions to expose more. The most common operations are `Host.ActiveEditors(0)` (the active editor) and [**Open**](#open) (jump to a file at a given line / column).

```tb check_build
' Read the selection out of the currently-focused code pane:
If Host.ActiveEditors.Count > 0 Then
    If TypeOf Host.ActiveEditors(0) Is CodeEditor Then
        Dim codeEditor As CodeEditor = Host.ActiveEditors(0)
        Host.DebugConsole.PrintText codeEditor.SelectedText
    End If
End If

' Navigate to a specific file + line + column:
Host.ActiveEditors.Open "twinbasic:/Sources/MainModule.twin", 42, 8
Host.ActiveEditors.Item(0).SetFocus
```

* TOC
{:toc}

## Properties

### Count
{: .no_toc }

Number of editors currently active. **Long**, read-only. Currently always **0** or **1**.

### Item
{: .no_toc }

Indexed access to the editor collection. **DefaultMember** --- so `Host.ActiveEditors(0)` is equivalent to `Host.ActiveEditors.Item(0)`.

Syntax: *editors*( *Index* ) **As** [**Editor**](/tB/Packages/tbIDE/Editor.md)

*Index*
: A zero-based **Variant** index. Currently `0` is the only valid value when an editor is open.

The returned object is an [**Editor**](/tB/Packages/tbIDE/Editor.md) but is usually castable to a more specific kind (e.g. [**CodeEditor**](/tB/Packages/tbIDE/CodeEditor.md) for a code pane) --- see [Editor castability](/tB/Packages/tbIDE/Editor.md#castability).

## Methods

### Open
{: .no_toc }

Opens (or re-focuses) the editor for a given file, optionally positioning the caret at a specific line and column.

Syntax: *editors*.**Open** *Path* [, *LineNumber* ] [, *ColumnNumber* ] [, *Options* ] [, *Designer* ]

*Path*
: *required* The virtual-FS path of the file to open. **String**. Typically starts with `"twinbasic:/"`; the value returned by [**FileSystemItem.Path**](/tB/Packages/tbIDE/FileSystemItem.md#path) or [**Editor.Path**](/tB/Packages/tbIDE/Editor.md#path) is always a valid argument.

*LineNumber*
: *optional* One-based line number to navigate to. **Long**. Default **0** (no navigation --- open the file at its remembered cursor position).

*ColumnNumber*
: *optional* One-based column number on the requested line. **Long**. Default **0** (column 1).

*Options*
: *optional* An [**EditorOpenOptions**](#editoropenoptions) value. Default [**NONE**](#EditorOpenOptions_NONE).

*Designer*
: *optional* A designer of the addin's own to open in a new tab, for no file. **As** [**Designer**](/tB/Packages/tbIDE/Designer.md). With it, *Path* and the other arguments are not used: the IDE opens a tab named *(unnamed)* and calls the designer's [**OnAttached**](/tB/Packages/tbIDE/Designer.md#onattached) and [**OnActivated**](/tB/Packages/tbIDE/Designer.md#onactivated), and no [**OnFileDataChanged**](/tB/Packages/tbIDE/Designer.md#onfiledatachanged). **Open** returns before **OnAttached** is called. The designer's [**DesignerHost.GetURI**](/tB/Packages/tbIDE/DesignerHost.md#geturi) is an empty string, and its [**Caption**](/tB/Packages/tbIDE/DesignerHost.md#caption) names the tab. After a restart of the compiler the tab shows *Sorry, unable to recover this document*.

Sample 26 opens its comparisons this way:

```tb inert=pseudo
Host.ActiveEditors.Open "", Designer:=New DiffCompareDesigner(Me, OriginalPath, ModifiedPath)
```

After **Open** returns, the requested file is the active editor; call `Editors.Item(0).SetFocus` to give it keyboard focus.

```tb check_build
Dim File As tbIDE.File
Dim LineNumber As Long, ColumnNumber As Long
Host.ActiveEditors.Open File.Path, LineNumber, ColumnNumber
Host.ActiveEditors.Item(0).SetFocus
```

## EditorOpenOptions
{: #editoropenoptions }

A flags enum declared inline on the **Editors** interface; consumed by [**Open**](#open). Currently a single-value placeholder --- additional flags may appear in later IDE versions.

| Constant | Value | Description |
|----------|-------|-------------|
| **NONE**{: #EditorOpenOptions_NONE } | 0 | No special open options. |
