draft_editor
The draft_editor
directory contains files that implement a "draft editor" feature for Talon. This allows users to quickly copy some text to a separate editor, edit it, and then paste the result back into the original location.
The core logic is found in draft_editor.py
. This Python file defines the actions and behavior of the draft editor.
Here's how it works:
- Tagging: It uses Talon tags (
draft_editor_active
,draft_editor_app_running
,draft_editor_app_focused
) to keep track of the state of the draft editor. - App Detection: It detects which application to use as the draft editor based on the
user.draft_editor
setting. If this setting is not configured, it defaults to a list of common code editor names like "Visual Studio Code" and "Code". It usesui.apps
to determine running applications. - Opening the Draft Editor: The
draft_editor_open
action opens a new tab in the configured draft editor application, pastes the selected text (if any) into it, and sets thedraft_editor_active
tag. - Submitting the Draft: The
draft_editor_submit
action selects all text in the editor, saves the selected text as thelast_draft
, closes the tab, and then attempts to return focus to the original window and paste the text. If focus cannot return to the original window, the user will need to manually focus the correct window, and use "draft submit" again. - Discarding the Draft: The
draft_editor_discard
action closes the draft editor tab without pasting it. - Pasting Last Draft: The
draft_editor_paste_last
action will paste the previously submittedlast_draft
.
The other .talon
files define the voice commands that interact with the Python logic:
draft_editor.talon
defines the commands used to open a draft editor from the main application.- "draft this" opens a draft editor with the current selection.
- "draft all" opens a draft editor with the entire document.
- "draft line" opens a draft editor with the current line.
- "draft top" opens a draft editor with content from the start of the file up to the cursor.
- "draft bottom" opens a draft editor with content from the cursor to the end of the file.
- "draft submit" pastes the last submitted draft. This can be used in case the user has to manually focus the intended destination, instead of using
draft_editor_submit
.
draft_editor_open.talon
defines the commands used when the draft editor is open and focused.- "draft submit" submits the current draft using
draft_editor_submit
. - "draft discard" discards the current draft using
draft_editor_discard
.
- "draft submit" submits the current draft using
In summary, this plugin provides a convenient way to use a text editor as a scratchpad for editing text within Talon. It uses tags, application detection, and actions to manage the draft editor's state and behavior.