Preview Updated 2026-05-10

CodeEditor

Lightweight code-editing container — textarea + line numbers + Tab indentation. Reach for Monaco / CodeMirror when you need full syntax / completion.

Basic usage

It’s positioned as “visual container + light interactions”: line numbers, Tab indentation, end-of-line preservation, and full ARIA labeling — but no built-in syntax highlighting. For highlighting, wrap an overlay around it on the consumer side (see the overlay technique used in VariableAwareInput).

12345678910
<CfCodeEditor v-model="code" language="typescript" :rows="12" />
<CfCodeEditor value={code} onChange={setCode} language="typescript" rows={12} />

readOnly / wrap / no line numbers

A handful of state combinations: read-only doc samples, soft-wrapped long text, and a no-line-number compact mode.

1234567
1
<CfCodeEditor v-model="code" read-only />
<CfCodeEditor v-model="text" wrap />
<CfCodeEditor v-model="snip" :show-line-numbers="false" />
<CfCodeEditor value={code} onChange={set} readOnly />
<CfCodeEditor value={text} onChange={set} wrap />
<CfCodeEditor value={snip} onChange={set} showLineNumbers={false} />

API

PropTypeDefaultDescription
modelValue / valuestring''Code content
languagestring'plaintext'Forwarded as data-language only; not used for rendering
size'sm' | 'md' | 'lg''md'
showLineNumbersbooleantrue
readOnlybooleanfalse
rowsnumber12Visible rows
wrapbooleanfalseSoft-wrap long lines
tabSizenumber2Number of spaces inserted by Tab; 0 makes Tab move focus

反馈与讨论

CodeEditor · Discussion

0
0 / 600
一键发送
正在加载评论...