Code editor
An editor for HTML, CSS, JavaScript, TypeScript, JSON and Markdown: syntax colours from the design tokens, line numbers, undo, smart indents, auto-closed brackets and tags, comments with Ctrl/⌘+/, search and replace, and form support. The page is rendered on the server as highlighted code and turns into the editor after hydration.
Its own package — install it separately, tectra-ng does not include it: npm install @tectra-ng/code-editor.
Basic
Bind the text with [(value)]; codeChanged reports every edit too. The language is html by default and the height 600px.
Languages
language takes html, css, javascript, typescript, json, markdown or plain (short names such as js, ts, md work too). Each language has its own colours, comment style and indent rules.
Form
The editor is a form control: formControl, ngModel and validators work, the frame turns red when the control is invalid and touched, and disabled follows the control.
Read only
readOnly keeps the cursor, selection, copy and search but blocks edits — for logs and generated code.
Search
Ctrl/⌘+F opens search, Ctrl+H (⌥⌘F on macOS) opens replace. Match case, whole word and regular expressions; Enter and Shift+Enter go through the matches, Escape closes. openSearch() opens it from code.
Options
Turn off lineNumbers, wordWrap or indentGuides, set tabSize (taken from the text when not set) and a placeholder for an empty editor.
Diff mode
diffMode with originalValue shows the changes from the original to value inline and scrolls to the first change; the new side stays editable unless readOnly. For more options use Code diff.
Design tokens
dt changes the tokens of one editor; syntax changes the colours of the tokens inside it.