Skip to content

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_cursors tag. 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_actions class, exposing a set of abstract functions such as multi_cursor_add_above(), multi_cursor_skip_occurrence(), and multi_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() or user.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:

  1. Activates the user.multiple_cursors tag when that editor is focused.
  2. Implements the multiple_cursor_actions class, translating functions like multi_cursor_add_above() into the editor's native hotkeys (e.g., sending ctrl-alt-up for VS Code on Windows, or cmd-ctrl-g for Sublime Text on macOS).