Struct CodeEditor

Source
pub struct CodeEditor<A = ()> { /* private fields */ }
Expand description

Code-oriented editor backed by an ailloli_ui_editor::Document signal.

Edits synchronize the document version/dirty flag, update the supplied signal, refresh syntax/search/folds, and then invoke the optional change handler. Defaults come from CodeEditorConfig; optional prop vectors replace their corresponding session models when enabled. The default wrap mode is no-wrap, so long lines scroll horizontally. Overflowing axes paint interactive overlay scrollbars whose thumbs can be dragged from the exact pressed point and whose track clicks center the thumb; those interactions never move the caret. Editing and keyboard navigation follow the caret on both axes and preserve three visible lines below it by default. A caret already in the safe region never moves the viewport. Clicks never move the viewport, and pointer selection auto-scrolls only outside the text viewport.

§Examples

use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new())));
let _ = editor;

Implementations§

Source§

impl<A: 'static> CodeEditor<A>

Source

pub fn width(self, value: impl Into<Length>) -> Self

Sets preferred width from a logical-pixel or length value.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().width(120.0);
let _ = widget;
Source

pub fn height(self, value: impl Into<Length>) -> Self

Sets preferred height from a logical-pixel or length value.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().height(40.0);
let _ = widget;
Source

pub fn min_width(self, value: impl Into<Length>) -> Self

Sets the minimum width bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_width(40.0);
let _ = widget;
Source

pub fn max_width(self, value: impl Into<Length>) -> Self

Sets the maximum width bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_width(320.0);
let _ = widget;
Source

pub fn min_height(self, value: impl Into<Length>) -> Self

Sets the minimum height bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_height(24.0);
let _ = widget;
Source

pub fn max_height(self, value: impl Into<Length>) -> Self

Sets the maximum height bound.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_height(240.0);
let _ = widget;
Source

pub fn fill(self) -> Self

Sets both preferred axes to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill();
let _ = widget;
Source

pub fn fill_width(self) -> Self

Sets preferred width to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_width();
let _ = widget;
Source

pub fn fill_height(self) -> Self

Sets preferred height to parent fill.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_height();
let _ = widget;
Source

pub fn margin(self, value: f32) -> Self

Sets uniform outer margin in logical pixels.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().margin(8.0);
let _ = widget;
Source

pub fn padding(self, value: f32) -> Self

Sets uniform inner padding in logical pixels.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().padding(8.0);
let _ = widget;
Source

pub fn flex_grow(self) -> Self

Sets flex-grow weight to one.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow();
let _ = widget;
Source

pub fn flex_grow_by(self, value: f32) -> Self

Sets a dimensionless flex-grow weight.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow_by(2.0);
let _ = widget;
Source

pub fn flex_shrink(self, value: f32) -> Self

Sets a dimensionless flex-shrink weight.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_shrink(1.0);
let _ = widget;
Source

pub fn flex_basis(self, value: impl Into<Length>) -> Self

Sets the preferred main-axis flex basis.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_basis(80.0);
let _ = widget;
Source

pub fn align_self(self, value: AlignItems) -> Self

Overrides cross-axis alignment for this flex item.

§Examples
use ailloli_ui_core::style::AlignItems;
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().align_self(AlignItems::Center);
let _ = widget;
Source§

impl<A: 'static> CodeEditor<A>

Source

pub fn new(document: impl Into<Signal<Document>>) -> Self

Creates a code editor bound to shared document state.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new())));
let _ = editor;
Source

pub fn language(self, language: EditorLanguage) -> Self

Forces one language instead of document/path-derived resolution.

§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorLanguage};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).language(EditorLanguage::Rust);
let _ = editor;
Source

pub fn theme(self, theme: CodeTheme) -> Self

Replaces code colors and synchronizes generic editor background/foreground.

§Examples
use ailloli_ui_editor::{CodeTheme, Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).theme(CodeTheme::dark());
let _ = editor;
Source

pub fn gutter(self, gutter: GutterConfig) -> Self

Replaces gutter enablement, width, line-number, fold, and diagnostic settings.

§Examples
use ailloli_ui_editor::{Document, DocumentId, GutterConfig};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).gutter(GutterConfig::default());
let _ = editor;
Source

pub fn features(self, features: CodeEditorFeatureFlags) -> Self

Replaces syntax/search/diagnostic/folding/symbol feature flags.

Disabled features clear or skip the corresponding retained model.

§Examples
use ailloli_ui_editor::{CodeEditorFeatureFlags, Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).features(CodeEditorFeatureFlags::default());
let _ = editor;
Source

pub fn line_numbers(self, enabled: bool) -> Self

Enables/disables line numbers and ensures the gutter is enabled when true.

Passing false hides line numbers but deliberately does not disable a gutter that may still show folds or diagnostics.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).line_numbers(false);
let _ = editor;
Source

pub fn wrap_mode(self, wrap_mode: EditorWrapMode) -> Self

Selects soft wrapping or horizontal no-wrap behavior.

§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorWrapMode};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).wrap_mode(EditorWrapMode::SoftWrap);
let _ = editor;
Source

pub fn scrollbars(self, enabled: bool) -> Self

Shows or hides editor-engine scrollbars without disabling scrolling.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).scrollbars(false);
let _ = editor;
Source

pub fn scrollbar_style(self, style: EditorScrollbarStyle) -> Self

Replaces editor scrollbar colors and logical-pixel geometry.

§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorScrollbarStyle};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).scrollbar_style(EditorScrollbarStyle::default());
let _ = editor;
Source

pub fn initial_scroll(self, x: f32, y: f32) -> Self

Sets initial x/y scroll offsets in logical pixels.

Each coordinate is floored at zero; negative and NaN values become zero. The offsets are reapplied when an external document replacement is observed, then normal editor metrics clamp them during frame building.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).initial_scroll(12.0, 24.0);
let _ = editor;
Source

pub fn search_query(self, query: SearchQuery) -> Self

Supplies the retained search query when search is enabled.

§Examples
use ailloli_ui_editor::{Document, DocumentId, SearchQuery};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).search_query(SearchQuery::new("fn"));
let _ = editor;
Source

pub fn search_active_match(self, active_match: usize) -> Self

Requests the active match index for the supplied search query.

Out-of-range handling is delegated to the editor search state.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).search_active_match(0);
let _ = editor;
Source

pub fn diagnostics(self, diagnostics: Vec<Diagnostic>) -> Self

Replaces local/LSP diagnostics when diagnostics are enabled.

Empty clears diagnostics; ranges remain UTF-8 byte ranges governed by the editor model.

§Examples
use ailloli_ui_editor::{Diagnostic, DiagnosticSeverity, Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let diagnostic = Diagnostic::new(0..1, DiagnosticSeverity::Warning, "check");
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::from_string("x")))).diagnostics(vec![diagnostic]);
let _ = editor;
Source

pub fn active_diagnostic(self, active_diagnostic: usize) -> Self

Requests one diagnostic index as active.

The value is forwarded without range validation; missing indexes simply produce no active diagnostic decoration/hit.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).active_diagnostic(0);
let _ = editor;
Source

pub fn fold_regions(self, fold_regions: Vec<FoldRegion>) -> Self

Replaces fold-region geometry when folding is enabled.

If IDs and line bounds match retained regions, their current collapsed state wins so a parent rebuild does not reopen user-toggled folds.

§Examples
use ailloli_ui_editor::{Document, DocumentId, FoldRegion};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).fold_regions(vec![FoldRegion::new(0, 2)]);
let _ = editor;
Source

pub fn symbol_summary(self, summary: CodeFileSummary) -> Self

Supplies a precomputed symbol graph when symbol support is enabled.

The current widget retains this metadata but has no symbol navigation UI; it does not alter paint output yet.

§Examples
use ailloli_ui_editor::{CodeFileSummary, Document, DocumentId, DocumentVersion, EditorLanguage};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let summary = CodeFileSummary { document_id: DocumentId(1), path: None, language: EditorLanguage::Rust, version: DocumentVersion(0), symbols: vec![], edges: vec![] };
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).symbol_summary(summary);
let _ = editor;
Source

pub fn initial_selection(self, anchor: usize, caret: usize) -> Self

Sets initial anchor/caret UTF-8 byte offsets.

Values are independently clamped to document byte length on first build, but are not ordered or validated as UTF-8 character boundaries.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::from_string("hello")))).initial_selection(0, 5);
let _ = editor;
Source

pub fn caret_follow_margin_lines(self, lines: f32) -> Self

Sets the visible-line safety margin kept below the revealed caret.

The default is three lines. The margin applies to edits, paste, undo, redo, IME changes, and keyboard navigation. Reveal always adds only the distance by which the caret crosses the safe boundary; pointer clicks never request caret following. Negative values become zero and non-finite values restore the default.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(
    DocumentId(1),
    TextBuffer::new(),
)))
.caret_follow_margin_lines(5.0);
let _ = editor;
Source

pub fn on_document_change(self, f: impl Fn(Document) -> A + 'static) -> Self

Maps each edited document into an application action.

The handler runs only after a text-changing edit has synchronized the document, not for selection, scroll, or external prop updates.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
enum Action { Changed(Document) }
let editor: CodeEditor<Action> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).on_document_change(Action::Changed);
let _ = editor;
Source

pub fn on_document_change_ctx( self, f: impl Fn(&mut EventCtx<A>, Document) + 'static, ) -> Self

Handles edited documents with mutable runtime event-context access.

§Examples
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_runtime::component::State;
use ailloli_ui_text::TextBuffer;
use ailloli_ui_widgets::editor::CodeEditor;
let editor: CodeEditor<()> = CodeEditor::new(State::new(Document::new(DocumentId(1), TextBuffer::new()))).on_document_change_ctx(|_ctx, _document| {});
let _ = editor;

Trait Implementations§

Source§

impl<A: 'static> IntoView<A> for CodeEditor<A>

Converts the builder into a retained code-editor component with layout hints.

Source§

fn into_view(self) -> View<A>

Consumes a builder/value and returns its declarative view tree. Read more
Source§

impl<A: 'static> LayoutExt for CodeEditor<A>

Source§

fn layout_mut(&mut self) -> &mut LayoutStyle

Returns the widget’s mutable declarative size/inset state. Read more

Auto Trait Implementations§

§

impl<A> Freeze for CodeEditor<A>

§

impl<A = ()> !RefUnwindSafe for CodeEditor<A>

§

impl<A = ()> !Send for CodeEditor<A>

§

impl<A = ()> !Sync for CodeEditor<A>

§

impl<A> Unpin for CodeEditor<A>

§

impl<A = ()> !UnwindSafe for CodeEditor<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, A> FlexItemExt<A> for T
where T: IntoView<A>,

Source§

fn flex_grow(self) -> View<A>

Sets flex-grow weight to one. Read more
Source§

fn flex_grow_by(self, value: f32) -> View<A>

Sets the dimensionless flex-grow weight. Read more
Source§

fn flex_shrink(self, value: f32) -> View<A>

Sets the dimensionless flex-shrink weight. Read more
Source§

fn flex_basis(self, value: impl Into<Length>) -> View<A>

Sets the preferred main-axis flex basis. Read more
Source§

fn align_self(self, value: AlignItems) -> View<A>

Overrides the parent cross-axis alignment for this view. Read more
Source§

fn fill_width(self) -> View<A>

Marks width as parent-fill in the view size hint. Read more
Source§

fn fill_height(self) -> View<A>

Marks height as parent-fill in the view size hint. Read more
Source§

fn fill(self) -> View<A>

Marks both axes as parent-fill in the view size hint. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, A> IntoViewKeyExt<A> for T
where T: IntoView<A>,

§

fn key(self, key: impl Into<String>) -> View<A>

Converts self, assigns the owned key, and returns the view. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,