Hi CodeMirror community,
I’m working on the Prometheus web UI (query editor), which uses CodeMirror 6 for PromQL completion and snippet insertion. I’m running into persistent trouble with snippet placeholder navigation: despite following all CodeMirror documentation, I can only get the first placeholder field to be editable—TAB does not cycle through additional fields as expected.
Reference File and Current Snippet Block
File:
web/ui/module/codemirror-promql/src/complete/promql.terms.ts
Current code:
typescript
{
label: 'histogram_quantile(\__quantile_\_, sum by(le) (rate(\__histogram_metric_\_\[5m\])))',
type: 'function',
detail: 'snippet',
info: 'Approximate a quantile value from an aggregated histogram',
apply: snippet('histogram_quantile(${\__quantile_\_}, sum by(le) (rate(${\__histogram_metric_\_}\[5m\])))'),
},
….other snippets.
Symptoms and Current Behavior
-
When a snippet is inserted in the editor, only the first placeholder (e.g.,
${__input_vector__}) is active/selected. -
Pressing TAB does not cycle through remaining fields (e.g.,
${__dst__},${__replacement__}, etc.). -
All other fields are static text, not editable placeholders.
What I’ve Tried So Far
-
Updated Placeholders to Numbered Format:
-
Changed all snippet fields to use the CodeMirror-recommended numbered format:
${1:input_vector},${2:dst}, etc. -
No change in behavior—still only the first field editable and tab-navigable.
-
-
Checked Editor Setup and Keymap:
-
Verified
import { snippet } from '@codemirror/autocomplete'and keymap extension setup. -
Made sure
snippetKeymap(from@codemirror/autocomplete) is present in my editor config:typescriptimport{ keymap }from"@codemirror/view";import{ snippetKeymap }from"@codemirror/autocomplete"; keymap.of([...snippetKeymap]);
-
-
CodeMirror Documentation and Examples:
- Read all official docs and forum threads (ref), which claim TAB navigation should work with numbered placeholders.
Dependencies and Environment
-
Using CodeMirror 6 latest (
@codemirror/autocomplete,@codemirror/view, etc.). -
No overriding/forked editor setup.
-
Inspected other repos and demos; most show expected behavior for snippets, but my implementation doesn’t work.
Questions for the Community
-
Is there something else I need to do in my autocomplete/snippet setup in CodeMirror 6 to enable multi-field TAB navigation?
-
Is my placeholder format (
${__name__}or${1:name}) incorrect or insufficient? -
Is there any nuance or caveat to how snippet fields must be defined or passed to
snippet()for correct behavior? -
Has anyone else seen a bugged/“malformed” snippet string improve navigation, and if so, what was the underlying cause?
-
Are there proven, open-source implementations I can use as reference for correct multi-field snippet navigation?
Thanks in advance for your help.
