layouts
All repositories: gitoria
2.9 KB
# Code editorA code field: the code is **coloured while you type**, line numbers follow, **Tab** indents and **Shift+Tab** outdents,**Ctrl+Z / Ctrl+Shift+Z** undo and redo. A port of custom-ide's CodeJar editor as a pure Hybriel component: no JavaScriptof its own. Demo: `/code-editor`.Use it in a page:```import CodeEditor from './code-editor.hl'form { method = "post" action = "/save"CodeEditor { name = "source" value = "let x = 1" language = "js" }}```## FilesCopy `code-editor.hl` (one file; it has its own `Style`). Nothing else. Every colour is `var(--color-…, <base value>)`(the syntax colours use the palette tokens `--orange`, `--green-light`, `--yellow`, `--green-dark`): without them the code isblack and the syntax greys (the base look: black, white, greys, no frames — root README "Look"); an app that declares theWorldAPI tokens (and its `--color-accent`) restyles it.## Attributes| Attribute | Meaning ||---|---|| `name` | the field name the text posts under (default `code`) || `value` | the start text || `language` | `hybriel` (default), `js` (or `javascript`), `plain` (no colours) || `spaces` | 0 (default): Tab writes a tab character; N: Tab writes N spaces |## What it does- **Highlighting** while typing: comments (`//`, `/* */`), strings (`'` `"` `` ` ``), numbers, keywords, function names (a namebefore `(`), Capitalised names (types). The caret stays where it was.- **Line numbers** in a gutter that follows the number of lines (it scrolls sideways with the code).- **Tab / Shift+Tab**: at the caret a tab (or `spaces` spaces) is inserted / removed; with several lines selected every line isindented / outdented.- **Enter** keeps the indent of the line; after `(` `[` `{` it indents once more, and a closing bracket right behind the caretmoves to its own line.- **Brackets and quotes** close themselves (a selection is wrapped); typing the closing character right before the same onesteps over it; an apostrophe inside a word (`don't`) stays alone.- **Undo / redo**: Ctrl+Z, Ctrl+Shift+Z (or Ctrl+Y). The editor keeps its own history (snapshots of text and caret, 300 atmost); typing within 300 ms is one step, Enter / Tab / a bracket / a paste are their own steps.- **Paste** is taken as plain text; the text is never treated as HTML.## Reading the valueThe text is in a hidden `<input name>`, so it posts in a form. A change is announced with a bubbling DOM `input` event on thatfield (`e.target.name`, `e.target.value`); the demo shows it below each editor:```form { on input(e) { emit gotCode(e) } … }on gotCode(e) { if (e.target.name == 'source') { source = e.target.value } }```## Not in it (custom-ide has more)Search, minimap, breadcrumbs, change bars, per-language grammars beyond the three above, read-only mode. Not tested: Firefox,Safari, touch, IME input (composition is left alone until it ends), very large files. Editing needs the page to be live(Hybriel has no mount event; the code appears when the page has loaded).
Branches
Latest commits
- 6385ff8eRecord LY7 style formatting proof and review statusmre
- 0100f51etracker-demo: format Style with nested rules and bare mediamre
- 5f82554enotes-demo: format Style with nested rules and bare mediamre
- 3dc27d78mail-demo: format Style with nested rules and bare mediamre
- cf9648afhome: format Style with nested rules and bare mediamre
- 846a6242user-menu: format Style with nested rules and bare mediamre
- 4d58708cthree-pane: format Style with nested rules and bare mediamre
- 0bbfc553main-menu: format Style with nested rules and bare mediamre
- 7755199dlist-first: format Style with nested rules and bare mediamre
- 35199303content-first: format Style with nested rules and bare mediamre
- 00f6e698app-sidebar: format Style with nested rules and bare mediamre
- bb2f29c9app-header: format Style with nested rules and bare mediamre
- 3aca2d7fSync components from 8176eb1 with reviewed nested stylesmre
- 87e4003dRe-vendor layouts to Hybriel set day35mre
- d8628cfflayouts: a startup error prints its message before exit 1 (hybriel#247)mre
- 180fd76elayouts: MdEditor from components 59704ce (text on the clipboard always pastes, a file manager copy still attaches; pipe rows; empty Table-button table; tickets#49, notes#5)mre
- a3eda8afRe-vendor Hybriel master 7a684920 (binary 74ab3715): plugins whole, startup fault exits 1; files-upload gate 340/0mre
- 025d5880WIP re-vendor Hybriel set-day27b (a9712e61, master f5ff97bf): plugins whole, startup fault exits 1; NOT deployable: files-upload emit refused (see .scratch/rv27-upload)mre
- 42183a71Merge sb3-standby: layouts deploys through its standbymre
- 408de1f2layouts: no jobs switch needed in the standbymre