gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9f3516999f351699Preserve comments and nest supported selectors without changing rendered outputmre9f351699/components/code-editor/README.md

2.9 KB

  1. # Code editor
  2. A code field: the code is **coloured while you type**, line numbers follow, **Tab** indents and **Shift+Tab** outdents,
  3. **Ctrl+Z / Ctrl+Shift+Z** undo and redo. A port of custom-ide's CodeJar editor as a pure Hybriel component: no JavaScript
  4. of its own. Demo: `/code-editor`.
  5. Use it in a page:
  6. ```
  7. import CodeEditor from './code-editor.hl'
  8. form { method = "post" action = "/save"
  9. CodeEditor { name = "source" value = "let x = 1" language = "js" }
  10. }
  11. ```
  12. ## Files
  13. Copy `code-editor.hl` (one file; it has its own `Style`). Nothing else. Every colour is `var(--color-…, <base value>)`
  14. (the syntax colours use the palette tokens `--orange`, `--green-light`, `--yellow`, `--green-dark`): without them the code is
  15. black and the syntax greys (the base look: black, white, greys, no frames — root README "Look"); an app that declares the
  16. WorldAPI tokens (and its `--color-accent`) restyles it.
  17. ## Attributes
  18. | Attribute | Meaning |
  19. |---|---|
  20. | `name` | the field name the text posts under (default `code`) |
  21. | `value` | the start text |
  22. | `language` | `hybriel` (default), `js` (or `javascript`), `plain` (no colours) |
  23. | `spaces` | 0 (default): Tab writes a tab character; N: Tab writes N spaces |
  24. ## What it does
  25. - **Highlighting** while typing: comments (`//`, `/* */`), strings (`'` `"` `` ` ``), numbers, keywords, function names (a name
  26. before `(`), Capitalised names (types). The caret stays where it was.
  27. - **Line numbers** in a gutter that follows the number of lines (it scrolls sideways with the code).
  28. - **Tab / Shift+Tab**: at the caret a tab (or `spaces` spaces) is inserted / removed; with several lines selected every line is
  29. indented / outdented.
  30. - **Enter** keeps the indent of the line; after `(` `[` `{` it indents once more, and a closing bracket right behind the caret
  31. moves to its own line.
  32. - **Brackets and quotes** close themselves (a selection is wrapped); typing the closing character right before the same one
  33. steps over it; an apostrophe inside a word (`don't`) stays alone.
  34. - **Undo / redo**: Ctrl+Z, Ctrl+Shift+Z (or Ctrl+Y). The editor keeps its own history (snapshots of text and caret, 300 at
  35. most); typing within 300 ms is one step, Enter / Tab / a bracket / a paste are their own steps.
  36. - **Paste** is taken as plain text; the text is never treated as HTML.
  37. ## Reading the value
  38. The text is in a hidden `<input name>`, so it posts in a form. A change is announced with a bubbling DOM `input` event on that
  39. field (`e.target.name`, `e.target.value`); the demo shows it below each editor:
  40. ```
  41. form { on input(e) { emit gotCode(e) } … }
  42. on gotCode(e) { if (e.target.name == 'source') { source = e.target.value } }
  43. ```
  44. ## Not in it (custom-ide has more)
  45. Search, minimap, breadcrumbs, change bars, per-language grammars beyond the three above, read-only mode. Not tested: Firefox,
  46. Safari, touch, IME input (composition is left alone until it ends), very large files. Editing needs the page to be live
  47. (Hybriel has no mount event; the code appears when the page has loaded).

Branches

Latest commits

  • 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
  • 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
  • ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
  • 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
  • b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre
  • ebd00b6cNest caller slot styles in three-panemre
  • 009991efNest caller slot styles in list-firstmre
  • 494d75d4Nest caller slot styles in app-sidebarmre
  • e5571680Align all plugin sources with Hybriel day38bmre
  • 5d204c46Re-vendor layouts to Hybriel set day38bmre
  • 17e0f03eNest html-prefixed theme component overridesmre
  • e54e735eFormat plain theme elements with nested rules and bare mediamre
  • 547f834eRecord LY7 deployment and live verificationmre
  • fa4600b1Link caller-slot style exceptions to hybriel#270mre
  • 413b11e1Record corrected LY7 nesting, exact CSS and Chrome proofmre
  • b810453etracker-demo: nest child and compound selectors in Stylemre
  • 0b5b1d61notes-demo: nest child and compound selectors in Stylemre
  • ab22bdc2mail-demo: nest child and compound selectors in Stylemre
  • fe2d8de9home: nest child and compound selectors in Stylemre