multiple_cursors
This directory defines a standardized, application-agnostic interface for controlling multiple cursors (multi-cursor/multi-select editing) using Talon voice commands.
Since different text editors and IDEs (such as VS Code, Sublime Text, or JetBrains) use entirely different keyboard shortcuts to manage multiple cursors, this module decouples the user's spoken commands from the underlying application-specific hotkeys.
How It Works
The multi-cursor functionality is split into two primary components: an abstract action interface and a voice command map.
1. Defining the Interface
The multiple_cursors.py file serves as the API definition. It performs two key tasks:
- Tag Declaration: It registers the
user.multiple_cursorstag. This tag acts as a capability flag. Application-specific contexts (e.g., a VS Code context) can "activate" this tag to signal to Talon that they support multi-cursor operations. - Action Declaration: It defines the
multiple_cursor_actionsclass, exposing a set of abstract functions such asmulti_cursor_add_above(),multi_cursor_skip_occurrence(), andmulti_cursor_select_all_occurrences(). These functions have no implementation details in this file; they are designed to be overridden by application-specific scripts.
2. Binding Voice Commands
The multiple_cursors.talon file maps natural voice triggers to the abstract actions defined in the Python file.
This file starts with the header:
tag: user.multiple_cursors
-
This ensures that the voice commands are only active and listening when the current application has enabled the user.multiple_cursors tag.
The command mappings include:
- "cursor up" / "cursor down": Triggers
user.multi_cursor_add_above()oruser.multi_cursor_add_below(). - "cursor more" / "cursor less": Adds or removes cursors based on occurrences of the current selection.
- "cursor skip": Skips the next occurrence of a selection while keeping existing cursors.
- "cursor all": Standardizes selection of all matches of the current word or selection.
- "cursor lines": Appends cursors to the end of all selected lines.
Integration Pattern
To implement this interface for a specific editor, a developer would create an application-specific context file elsewhere in the repository that:
- Activates the
user.multiple_cursorstag when that editor is focused. - Implements the
multiple_cursor_actionsclass, translating functions likemulti_cursor_add_above()into the editor's native hotkeys (e.g., sendingctrl-alt-upfor VS Code on Windows, orcmd-ctrl-gfor Sublime Text on macOS).