---
title: "DroppyMarkdownEditorContext, DroppyKit"
description: "Everything the host editor needs beyond the text binding (DroppyKit 0.2.2)."
canonical: "https://getdroppy.app/docs/droppykit/api/droppy-markdown-editor-context"
last-updated: "2026-09-09"
---

# DroppyMarkdownEditorContext

Everything the host editor needs beyond the text binding (DroppyKit 0.2.2).

`struct DroppyMarkdownEditorContext`

A struct rather than a longer parameter list so future additions stay additive: the factory signature never has to change again.

## Initializers

### init(documentID:placeholder:commands:onFocusChange:autoFocus:restoreSelectionLocation:onSelectionChange:)

`init(documentID: AnyHashable? = nil, placeholder: String = "Start typing…", commands: DroppyMarkdownEditorCommands? = nil, onFocusChange: ((Bool) -> Void)? = nil, autoFocus: Bool = false, restoreSelectionLocation: Int? = nil, onSelectionChange: ((Int) -> Void)? = nil)`

Creates a context. Every field defaults, so `.init()` is the plain editor.

## Properties

### autoFocus

`var autoFocus: Bool`

When true the editor takes first responder on mount and on every document switch, so typing works without an extra click.

### commands

`var commands: DroppyMarkdownEditorCommands?`

Optional command bus wired to the droplet's formatting bar.

### documentID

`var documentID: AnyHashable?`

Stable identity of the document being edited. The host watches this to notice a document switch while the editor stays mounted, and reloads instead of routing the new document's edits into the old one.

### onFocusChange

`var onFocusChange: ((Bool) -> Void)?`

Called with `true` when editing starts and `false` when it ends, so the host can stand its own key handling down while a droplet types.

### onSelectionChange

`var onSelectionChange: ((Int) -> Void)?`

Called as the caret moves, so the droplet can persist it per document.

### placeholder

`var placeholder: String`

Placeholder shown while the document is empty.

### restoreSelectionLocation

`var restoreSelectionLocation: Int?`

Caret location (UTF-16 offset) to restore when the editor gains focus, so a document reopens where the user left off instead of at the top.
