Skip to content

CodeEditor ​

CodeEditor is a lightweight code input with a controlled value, syntax highlighting, line numbers, placeholder text, and read-only state. It uses contenteditable="plaintext-only" and the CSS Custom Highlight API, not Monaco. It is a Lab component and ships only under the canary tag.

Import ​

ts
import { CodeEditor } from '@astryx-vue/lab'

Props ​

NameTypeDefaultDescription
valuestringRequiredThe controlled text.
labelstringRequiredAccessible name of the editable region.
languagestring'plaintext'Highlighting language.
hasLineNumbersbooleanfalseShows the line-number gutter.
isReadOnlybooleanfalseRead-only; the text remains focusable and selectable.
placeholderstringundefinedPlaceholder shown when the value is empty.
maxHeightnumber | stringundefinedMaximum content height before scrolling.
size'sm' | 'md''md'Code text size.
tokenizer(code, language) => TokenLine[]Core tokenizerCustom syntax parser.
escapeHintstringEnglish hintTells assistive technology how to leave the Tab-indenting editor.

Events ​

change carries the latest text:

vue
<CodeEditor :value="source" label="Source code" @change="source = $event" />

Keyboard ​

  • Tab inserts two spaces.
  • Shift+Tab removes up to two leading spaces on the current line.
  • Enter preserves the current indentation.
  • Brackets and quotes auto-close, with the caret between the pair.
  • Because Tab indents, press Escape once and then Tab or Shift+Tab to leave. This escape mode is one-shot. Typing again restores ordinary indentation.
  • Assistive technology reads escapeHint through aria-describedby. Override it for localization.

Highlighting uses the CSS Custom Highlight API and does not insert syntax nodes into the editable text. Large text uses the core async tokenizer; old ranges are cleaned up on change and unmount.