The Type Ahead experiment adds inline ghost-text completions to the block editor. When enabled, supported blocks show AI suggestions at the caret that can be accepted fully or incrementally with keyboard shortcuts.
When enabled, type-ahead suggestions appear while writing in supported blocks:
- Suggestions are generated when the caret is at the end of a selected supported block.
- Suggestions can appear in empty paragraph blocks as well as non-empty blocks.
- In empty blocks, the Gutenberg placeholder (
Type / to choose a block) is hidden while ghost text is visible to prevent overlap. - Keyboard shortcuts:
Tab: accept the full suggestion.Cmd/Ctrl + Right Arrow: accept the next word.Cmd/Ctrl + Shift + Right Arrow: accept the next sentence.Esc: dismiss current suggestion.Cmd/Ctrl + Space: manual trigger.
The experiment has three parts:
- Experiment Class (
WordPress\AI\Experiments\Type_Ahead\Type_Ahead): registers the ability, enqueues editor assets, and registers settings. - Ability Class (
WordPress\AI\Abilities\Type_Ahead\Type_Ahead): validates input, builds prompt context, calls AI, and returns structured{ suggestion, confidence }. - React Editor Integration (
src/experiments/type-ahead/): wraps supported blocks, tracks caret/context, requests suggestions, and renders ghost text.
WordPress\AI\Experiments\Type_Ahead\Type_Ahead::register() wires:
wp_abilities_api_init-> registersai/type-ahead.enqueue_block_editor_assets-> enqueuesexperiments/type-aheadJS.enqueue_block_assets-> enqueuesexperiments/type-aheadCSS.
Editor bootstrap:
src/experiments/type-ahead/index.tsxreadswindow.aiTypeAheadData, creates the allowed block set, and registers aneditor.BlockEditHOC (withAITypeAhead).
-
PHP side
- Enqueues script:
experiments/type-ahead. - Enqueues stylesheet:
experiments/type-ahead. - Localizes
window.aiTypeAheadDatawith:enabledcompletionModetriggerDelayconfidencemaxWordsshowHeadings
- Enqueues script:
-
React side
TypeAheadBlockresolves block/editable DOM nodes and caret details.useTypeAheadContextextracts plain block content, neighboring context, and post ID.useTypeAheadSuggestiondebounces requests and callsrunAbility( 'ai/type-ahead', input ).- Suggestions are rendered:
- inline ghost span when caret is not at end;
- overlay text when caret is at end.
- Accepted text is inserted and an
inputevent is dispatched so Gutenberg persists the change.
-
Ability side
- Truncates context fields to 5000 chars.
- Builds prompt JSON via
prepare_prompt_context(). - Uses JSON schema output (
suggestion,confidence) and validates/parses response. - Caches per
(block_content, preceding_text, mode, max_words)for 45 seconds.
- Requests run only when:
- experiment is enabled,
- block type is allowed (
core/paragraphplus optionalcore/heading), - current block is selected,
- caret is at block end.
- Empty block content is allowed.
- In
wordmode, auto-trigger additionally requires punctuation/context fromshouldTriggerFromContext(). - Manual trigger (
Cmd/Ctrl + Space) bypasses thewordmode context gate.
array(
'post_id' => array( 'type' => 'integer' ),
'block_content' => array( 'type' => 'string' ),
'preceding_text' => array( 'type' => 'string' ),
'following_text' => array( 'type' => 'string' ),
'surrounding_context' => array( 'type' => 'string' ),
'cursor_position' => array( 'type' => 'integer' ),
'mode' => array( 'type' => 'string', 'enum' => array( 'word', 'sentence', 'paragraph', 'smart' ) ),
'max_words' => array( 'type' => 'integer' ),
'manual_trigger' => array( 'type' => 'boolean' ),
)array(
'type' => 'object',
'properties' => array(
'suggestion' => array( 'type' => 'string' ),
'confidence' => array( 'type' => 'number' ),
'cursor_position' => array( 'type' => 'integer' ),
),
)The ability's permission_callback has two paths:
- With
post_id: requires existing post,edit_postcapability, andshow_in_restpost type. - Without
post_id: requiresedit_posts.
- Enable global experiments and Type-ahead Text in settings.
- Open block editor and verify suggestions appear in:
- non-empty paragraphs;
- empty paragraph blocks.
- In an empty paragraph with active ghost text, verify placeholder text does not overlap.
- Verify keyboard controls (
Tab,Cmd/Ctrl + Right,Cmd/Ctrl + Shift + Right,Esc,Cmd/Ctrl + Space). - Enable headings in settings and verify
core/headingsupport. - In
wordmode, verify auto-trigger only happens in triggering contexts, while manual trigger still works.