> ## Documentation Index
> Fetch the complete documentation index at: https://klyx.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Editor & Workspace Tabs

Extensions can interact with Klyx's editor through file openers, workspace tabs, and editor actions.

## FileOpenerRegistry

Register custom file openers to handle opening files with specific extensions.

### Register an opener

```kotlin theme={null}
private val openers: FileOpenerRegistry by plugin()

openers.register(object : FileOpener {
    override val id = "myext.opener"
    override val priority = 50
    override suspend fun open(request: FileOpenRequest): WorkspaceTab? {
        if (request.extension != "svg") return null
        return WorkspaceTab.Custom(
            title = request.fileName,
            content = { SvgViewer(request.uri) }
        )
    }
})
```

Return `null` to let other openers try. Higher `priority` values are tried first.

### FileOpenRequest

```kotlin theme={null}
data class FileOpenRequest(
    val uri: Uri,           // File URI
    val fileName: String,   // Display name
    val extension: String,  // File extension without dot
    val mimeType: String?,  // MIME type if available
    val projectUri: Uri?    // Project URI if inside a project
)
```

## WorkspaceTab

A `WorkspaceTab` represents an open tab in Klyx's workspace.

| Type                     | Description                        |
| ------------------------ | ---------------------------------- |
| `WorkspaceTab.TextFile`  | Text file with syntax highlighting |
| `WorkspaceTab.ImageFile` | Image viewer                       |
| `WorkspaceTab.Welcome`   | Welcome screen                     |
| `WorkspaceTab.Custom`    | Any custom composable content      |

### Custom tab

```kotlin theme={null}
WorkspaceTab.Custom(
    title = request.fileName,
    id = request.uri.toString(),
    content = { MyCustomViewer() }
)
```

### TextFile tab

```kotlin theme={null}
WorkspaceTab.TextFile(
    file = kxFile,
    title = kxFile.name
)
```

## Tabs service

Manage open workspace tabs.

```kotlin theme={null}
private val tabs: Tabs by plugin()
```

| Function     | Returns              | Description              |
| ------------ | -------------------- | ------------------------ |
| `current`    | `WorkspaceTab?`      | The currently active tab |
| `opened`     | `List<WorkspaceTab>` | All open tabs            |
| `open(tab)`  |                      | Open a tab               |
| `close(id)`  |                      | Close a tab by ID        |
| `select(id)` |                      | Switch to a tab          |
| `get(id)`    | `WorkspaceTab?`      | Get a tab by ID          |

## EditorAction

`EditorAction` represents actions that can be performed on editor content.

| Action                                   | Description                     |
| ---------------------------------------- | ------------------------------- |
| `EditorAction.Save(kxFile)`              | Save the current file           |
| `EditorAction.SaveAs(oldTabId, newFile)` | Save the file to a new location |
