Editor helper functions enable rich text editing experiences by mapping between text queries/selections and their corresponding timestamped tokens.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragaeeb/paragrafs/llms.txt
Use this file to discover all available pages before exploring further.
getFirstMatchingToken
Searches through an array of tokens and returns the first one whose text sequence matches the given query string. This function uses normalized hint matching for robust searching.Parameters
An ordered array of Token objects to search
A string containing one or more words to match. If you pass multiple words (e.g. “hello world”), it will only match if “hello” at position
i is immediately followed by “world” at position i+1.Returns
The first Token in the array where the hint sequence matches, or
null if no matching sequence is foundExample
Use Cases
- Jump to timestamp: Allow users to search for a phrase and jump to its timestamp in a video/audio player
- Highlight matching: Find and highlight all occurrences of a search term in a transcript viewer
- Navigation: Enable keyboard shortcuts to jump between search results
getFirstTokenForSelection
Finds and returns the first token in a segment whose character range fully contains the given[selectionStart, selectionEnd) range.
This is useful when you have a selection in the raw segment.text (for example, from an <input>’s selectionStart and selectionEnd) and you want to map that back to the corresponding timed Token.
Parameters
The Segment object containing the full
text and an ordered list of tokensThe zero-based index into
segment.text where the selection begins (inclusive)The zero-based index into
segment.text where the selection ends (exclusive)Returns
The first Token whose span in
segment.text covers the entire selection range, or null if not foundExample
Use Cases
- Text editor integration: Map cursor position or text selection to timestamp for audio/video synchronization
- Rich text editing: Allow users to click on a word in a transcript and jump to that point in the media
- Selection-based actions: Enable features like “play from selection” or “edit selected word”
- Duplicate word handling: The function correctly handles duplicate words by tracking position in the text