text_navigation
This directory contains a powerful pattern-based text navigation and editing module. Instead of relying solely on repetitive cursor movements, this plugin allows you to jump to, select, delete, copy, or cut text relative to specific patterns (such as punctuation, camelCase words, bracketed text, or specific phrases) on the current line or adjacent lines.
Core Architecture
The text navigation system works by capturing a snapshot of the surrounding text using standard editor selections, running regular expressions on that text to find the target pattern, and then calculating and executing the precise sequence of keyboard commands to position the cursor or select the targeted text block.
The implementation is split across the following files:
- text_navigation.talon: Defines the main voice grammars and provides several fast-access commands for common navigation patterns.
- text_navigation.py: Implements the text extraction logic, regular expression target matching, and cursor coordinate calculation.
- navigation_action.talon-list: Enumerates the supported structural editing actions (
move,extend,select,clear,cut,copy). - before_or_after.talon-list: Provides the positioning modifiers (
beforeorafter) that dictate where actions should occur relative to a matched pattern.
Grammar and Voice Command Interface
The primary interface is declared in text_navigation.talon. The main grammar is highly flexible:
navigate [{user.arrow_key}] [{user.navigation_action}] [{user.navigation_target_name}] [{user.before_or_after}] [<user.ordinals>] <user.navigation_target>:
This structure accepts:
- Direction (
arrow_key): Left, right, up, or down (defaults toright). - Action (
navigation_action): What to do when the target is found, such as moving the cursor, extending a selection, or cutting the text. Defined in navigation_action.talon-list. - Scope/Structural Unit (
navigation_target_name): The type of block to manipulate (such as a standardword, asmallcamelCase word, abigwhitespace-delimited block, or bracket contents likeparensorbraces). - Position Modifier (
before_or_after): Dictates whether actions apply prior to or following the target. Defined in before_or_after.talon-list. - Occurrence (
ordinals): Which instance to target (e.g., "second", "third"). Defaults to the first. - The Pattern Target (
navigation_target): The actual character, string, or named pattern to search for.
The file also includes quick-access commands for fast word-level navigation:
* word neck / word pre (select next/previous word)
* small word neck / small word pre (select next/previous sub-word in camelCase)
* big word neck / big word pre (select next/previous whitespace-delimited chunk)
Execution and Text Scanning
Because Talon does not always have access to a direct buffer API in every text editor, text_navigation.py implements "virtual selection parsing" to read text on the screen:
- Text Extraction: Based on the requested direction (
LEFT,RIGHT,UP, orDOWN), the Python script issues selection actions (e.g.,actions.edit.extend_line_start()or extending upward a certain number of lines) and callsactions.edit.selected_text()to pull the surrounding text into memory. - Configurable Boundary: When searching
UPorDOWN, the plugin looks up or down a specified number of lines. This maximum limit is governed by the settingtext_navigation_max_line_search, which defaults to10lines. - Regular Expression Matching:
- Targets are mapped to regular expressions in the
navigation_target_namesdictionary. This defines patterns for matching structures likeparens(\((.*?)\)), constants ([A-Z_][A-Z_]+), and camelCase components ([A-Z]?[a-z0-9]+). - Depending on the direction of search, the engine executes
match_forwardormatch_backwardsto locate the target index relative to the cursor's current location.
- Targets are mapped to regular expressions in the
- Cursor Orchestration: Once the target coordinates within the text block are resolved, the script resets the original cursor position and sends discrete keystrokes (
go_left,go_right,extend_left,extend_right) to move or select precisely to the matched region, executing the final action (such as copy, cut, or delete) if required.