Skip to content

draft_editor

The draft editor plugin allows you to compose and edit text inside a full-featured external text editor (such as Visual Studio Code) instead of limiting yourself to basic textareas, browser inputs, or fields with poor dictation support. Once you finish editing, the draft editor automatically returns focus to your original window and pastes the drafted text.

How the Draft Editor Works

The draft editor manages a state machine driven by Talon window events and tags.

  1. Background Tracking: The plugin actively monitors your open applications. When a supported editor (like VS Code) is launched, closed, or focused, Talon dynamically updates corresponding context tags (user.draft_editor_app_running and user.draft_editor_app_focused).
  2. Initiating a Draft: When you are typing in an application (e.g., a web browser) and invoke an initiation command (such as "draft this"), Talon stores a reference to your active window, copies any selected text, opens a new tab in your designated editor, and pastes the text.
  3. Editing: While you edit, the plugin switches context to recognize editor-specific submission commands.
  4. Submitting or Discarding:
    • Submit: Saying "draft submit" commands the editor to select all text, copy it, close the editor tab, switch back to your original window, and paste the updated content.
    • Discard: Saying "draft discard" deletes the temporary text in your editor, closes the tab, and returns you to the original window without altering the original input field.

Core Components

Python Orchestration

The logical backend is defined in draft_editor.py. It registers UI event hooks to track whether your editor is running or focused. Additionally, it exposes several key actions:

  • user.draft_editor_open(): Saves the current window state, focuses the editor, creates a new tab, and populates it with the selected text.
  • user.draft_editor_submit() / user.draft_editor_discard(): Orchestrates the closing sequences and handles focus restoration.
  • user.draft_editor_paste_last(): A fallback mechanism that lets you re-paste the most recently submitted draft in case focus restoration failed during auto-paste.

It also registers a user setting user.draft_editor, allowing you to customize which application behaves as your draft editor. By default, it looks for popular VS Code distributions:

default_names = ["Visual Studio Code", "Code", "VSCodium", "Codium", "code-oss"]

Voice Commands

The voice interface is split across two separate .talon files to ensure commands are context-aware and do not conflict.

draft_editor.talon

These commands are active only when your target editor is running but not currently focused. This ensures you can initiate a draft session from any other application (such as a browser, Slack, or email client).

Available commands include:

  • "draft this": Initiates drafting using currently selected text.
  • "draft all": Selects everything in the current input field and opens it in the draft editor.
  • "draft line": Selects the current line and opens it in the draft editor.
  • "draft top" / "draft bottom": Extends selection to the start or end of the document before sending it to the editor.
  • "draft submit": Manually triggers a paste of the last successfully closed draft.

draft_editor_open.talon

These commands are contextually constrained to be active only when a draft session is explicitly active and your target editor is focused.

  • "draft submit": Concludes the session, copying your work and pasting it back to your source window.
  • "draft discard": Aborts the session, closing the tab and returning focus to your source window without saving modifications.