From cd68f43c258b11a6f24f77e20069c6adb2cdbbac Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Thu, 5 Nov 2026 18:51:16 -0800 Subject: [PATCH] feat: expose editor viewport and line annotation props --- rust/src/ui/mod.rs | 51 ++++++++++++++++++++++++++++++++++++ typescript/src/props.ts | 12 +++++++++ typescript/test/jsx.test.tsx | 35 +++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/rust/src/ui/mod.rs b/rust/src/ui/mod.rs index 513c656..af84123 100644 --- a/rust/src/ui/mod.rs +++ b/rust/src/ui/mod.rs @@ -1420,6 +1420,8 @@ impl Editor { mode(String) = "mode"; /// The text is code in this language. lang(String) = "lang"; + /// Set false to use `decor` colors without native syntax highlighting (default true). + highlight(bool) = "highlight"; /// Not editable. readonly(bool) = "readonly"; /// Accepts an atomic `send`. @@ -1428,6 +1430,16 @@ impl Editor { typeahead(bool) = "typeahead"; /// Cap the height at this many lines. max_lines(u32) = "maxLines"; + /// Clip long lines instead of soft-wrapping them (default false). + nowrap(bool) = "nowrap"; + /// Zero-based line at the top; takes precedence over cursor following. + topline(u32) = "topline"; + /// Follow caret movement when `topline` is absent (default true); false preserves scroll. + follow_cursor(bool) = "followCursor"; + /// One entry per logical line, in a shared gutter; not part of the text or its offsets. + gutter(Vec) = "gutter"; + /// One entry per logical line, at its end; not part of the text or its offsets. + virt(Vec) = "virt"; /// The look (`field` frames it as a prompt input). variant(InputVariant) = "variant"; /// Buttons attached inside the ring, in order. @@ -2987,6 +2999,45 @@ mod tests { ); } + #[test] + fn editor_viewport_props_serialize() { + let source = "let café = \"🦆\";\nprint(café)\n"; + assert_eq!( + wire( + editor::<()>() + .text(source) + .cursor(4usize) + .highlight(false) + .nowrap(true) + .topline(0u32) + .follow_cursor(false) + .gutter(vec!["1 │ ".into(), span("2 │ ").style("accent").into(), "".into()]) + .virt(vec!["".into(), span(" : number").style("muted").into(), "end".into()]) + )["p"], + json!({ + "text": source, "cursor": 4, "highlight": false, "nowrap": true, + "topline": 0, "followCursor": false, + "gutter": ["1 │ ", [{"t": "2 │ ", "s": "accent"}], ""], + "virt": ["", [{"t": " : number", "s": "muted"}], "end"] + }) + ); + } + + #[test] + fn editor_viewport_props_are_optional_and_can_clear_line_annotations() { + assert_eq!(wire(editor::<()>())["p"], json!({})); + assert_eq!( + wire( + editor::<()>() + .gutter(vec!["1 │ ".into()]) + .virt(vec![" : number".into()]) + .gutter(vec![]) + .virt(vec![]) + )["p"], + json!({"gutter": [], "virt": []}) + ); + } + #[test] fn typed_values_and_escape_hatches_serialize() { let c = card::<()>() diff --git a/typescript/src/props.ts b/typescript/src/props.ts index fac8bad..5c38521 100644 --- a/typescript/src/props.ts +++ b/typescript/src/props.ts @@ -1237,7 +1237,19 @@ export interface InputProps extends FieldTextProps { /** Props of `editor`. */ export interface EditorProps extends FieldTextProps { + /** False disables syntax highlighting while keeping `lang`'s code presentation; default true. */ + readonly highlight?: boolean; readonly maxLines?: number; + /** Clip long lines instead of soft-wrapping; default false. */ + readonly nowrap?: boolean; + /** Zero-based logical line at the top; overrides automatic caret scrolling. */ + readonly topline?: number; + /** False preserves scrolling when the caret moves; default true. `topline` takes precedence. */ + readonly followCursor?: boolean; + /** One entry per logical line in a shared gutter column; not part of the text. */ + readonly gutter?: readonly Spans[]; + /** One entry per logical line, drawn at its end; not part of the text. */ + readonly virt?: readonly Spans[]; } /** Props of `status`. */ diff --git a/typescript/test/jsx.test.tsx b/typescript/test/jsx.test.tsx index 69d694e..54d108c 100644 --- a/typescript/test/jsx.test.tsx +++ b/typescript/test/jsx.test.tsx @@ -114,6 +114,41 @@ describe('TSX', () => { }); }); + test('editor viewport props and per-line spans survive typed JSX', () => { + const tree = ( + + ); + expect(json(tree)).toEqual({ + k: 'editor', + p: { + text: 'const π = "🌍";\nπ', + cursor: 0, + lang: 'javascript', + highlight: false, + nowrap: false, + topline: 0, + followCursor: false, + gutter: ['1 │ ', [{ t: '●', s: 'error' }, ' 2 ']], + virt: [' → 🌍', [{ t: '✓', s: 'success' }, ' 值']], + }, + }); + }); + + test('omitted editor viewport props leave defaults to Tern', () => { + expect(json()).toEqual({ k: 'editor', p: { text: 'draft' } }); + expect(json(ui.editor())).toEqual({ k: 'editor' }); + }); + test('meter cells carry the required meter wrapper on the wire', () => { const cells = { usage: { meter: { value: 0.5, title: 'Half' } } }; const table = ui.table({ cols: [{ id: 'usage' }], rows: [{ id: 'a', cells }] });