Skip to main content

Editor

Struct Editor 

Source
#[non_exhaustive]
pub struct Editor {
Show 24 fields pub id: WidgetId, pub rect: Rect, pub lines: Vec<EditorLine>, pub cursor: Option<EditorCursor>, pub extra_cursors: Vec<CursorPos>, pub selection: Option<EditorSelection>, pub extra_selections: Vec<EditorSelection>, pub yank_highlight: Option<EditorSelection>, pub scroll_top: usize, pub scroll_left: usize, pub total_lines: usize, pub max_col: usize, pub gutter_char_width: usize, pub is_active: bool, pub show_active_bg: bool, pub has_git_diff: bool, pub has_breakpoints: bool, pub diagnostic_gutter: HashMap<usize, DiagnosticSeverity>, pub code_action_lines: HashSet<usize>, pub bracket_match_positions: Vec<(usize, usize)>, pub active_indent_col: Option<usize>, pub tabstop: usize, pub cursorline: bool, pub lightbulb_glyph: char,
}
Expand description

Declarative description of one editor viewport (window / pane).

Mirrors vimcode::render::RenderedWindow field-for-field.

Adding a field here is a breaking change — this struct is #[non_exhaustive] to require use of Editor::new plus the with_* builder methods (besides id/rect) and a Default impl.

§Examples

use quadraui::{Editor, EditorHit, EditorLine, Rect, WidgetId};

let line = EditorLine {
    raw_text: "fn main() {}\n".to_string(),
    gutter_text: "  1".to_string(),
    spans: vec![],
    line_idx: 0,
    is_current_line: true,
    is_fold_header: false,
    folded_line_count: 0,
    git_diff: None,
    diff_status: None,
    diagnostics: vec![],
    spell_errors: vec![],
    is_breakpoint: false,
    is_conditional_bp: false,
    is_dap_current: false,
    is_wrap_continuation: false,
    segment_col_offset: 0,
    annotation: None,
    ghost_suffix: None,
    is_ghost_continuation: false,
    indent_guides: vec![],
    colorcolumns: vec![],
};

let rect = Rect::new(0.0, 0.0, 80.0, 24.0);
let editor = Editor::new(WidgetId::new("editor:main"), rect)
    .with_lines(vec![line])
    .with_total_lines(1)
    .with_gutter_char_width(3);

let layout = editor.layout(rect, 1.0, 1.0);
match layout.hit_test(5.0, 0.0) {
    EditorHit::BufferPos { line, .. } => assert_eq!(line, 0),
    other => panic!("expected a buffer-position hit, got {other:?}"),
}

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: WidgetId§rect: Rect

Pixel-space rectangle (used by GTK / Win-GUI; TUI ignores).

§lines: Vec<EditorLine>

Visible lines, one per row.

§cursor: Option<EditorCursor>

Primary cursor (position + shape). None when scrolled off-screen.

§extra_cursors: Vec<CursorPos>

Secondary cursor positions for multi-cursor (Alt-D). Drawn as dimmed blocks.

§selection: Option<EditorSelection>

Active visual selection.

§extra_selections: Vec<EditorSelection>

Extra selections for Ctrl+D word-multi-cursor.

§yank_highlight: Option<EditorSelection>

Transient post-yank flash region. None when no flash active.

§scroll_top: usize

Index of the first visible buffer line.

§scroll_left: usize

Number of character columns scrolled horizontally.

§total_lines: usize

Total lines in the buffer (drives vertical scrollbar geometry).

§max_col: usize

Max line length in the buffer (character cells, excl. trailing newline). Drives horizontal scrollbar.

§gutter_char_width: usize

Width of the line-number gutter in character cells (0 = no gutter). GTK multiplies by char_width to get pixels.

§is_active: bool

Whether this is the focused window.

§show_active_bg: bool

Whether to render with the slightly-different active-window background — only true when is_active AND there are multiple windows. Drives the rasteriser’s choice between theme.editor_active_background and theme.background.

§has_git_diff: bool

Whether the buffer has git diff data (controls git column).

§has_breakpoints: bool

Whether to show the breakpoint gutter column.

§diagnostic_gutter: HashMap<usize, DiagnosticSeverity>

Per-line worst diagnostic severity. Used for gutter icons.

§code_action_lines: HashSet<usize>

Lines with available LSP code actions (lightbulb gutter glyph).

§bracket_match_positions: Vec<(usize, usize)>

Bracket-pair positions to highlight (cursor bracket + match). Each (view_line, col). Up to 2 entries.

§active_indent_col: Option<usize>

Indent-guide column highlighted as “active” (cursor’s scope).

§tabstop: usize

Tab stop width for expanding \t to spaces (TUI rendering).

§cursorline: bool

Whether to draw cursorline highlight.

§lightbulb_glyph: char

Glyph the rasteriser draws in the gutter for lines with an available LSP code action. The host computes this from its icon registry per frame so nerd-font / fallback toggles propagate without the rasteriser depending on a host icon module. Apps without code-action icons can leave this at '\0' and the rasteriser skips painting.

Implementations§

Source§

impl Editor

Source

pub fn new(id: WidgetId, rect: Rect) -> Self

An editor viewport at rect with no lines, no cursor, and no overlays — chain with_* to fill it in.

Source

pub fn with_lines(self, lines: Vec<EditorLine>) -> Self

Replace Self::lines.

Source

pub fn with_cursor(self, cursor: EditorCursor) -> Self

Source

pub fn with_extra_cursors(self, extra_cursors: Vec<CursorPos>) -> Self

Source

pub fn with_selection(self, selection: EditorSelection) -> Self

Source

pub fn with_extra_selections( self, extra_selections: Vec<EditorSelection>, ) -> Self

Source

pub fn with_yank_highlight(self, yank_highlight: EditorSelection) -> Self

Source

pub fn with_scroll_top(self, scroll_top: usize) -> Self

Source

pub fn with_scroll_left(self, scroll_left: usize) -> Self

Source

pub fn with_total_lines(self, total_lines: usize) -> Self

Source

pub fn with_max_col(self, max_col: usize) -> Self

Source

pub fn with_gutter_char_width(self, gutter_char_width: usize) -> Self

Source

pub fn with_is_active(self, is_active: bool) -> Self

Source

pub fn with_show_active_bg(self, show_active_bg: bool) -> Self

Source

pub fn with_has_git_diff(self, has_git_diff: bool) -> Self

Source

pub fn with_has_breakpoints(self, has_breakpoints: bool) -> Self

Source

pub fn with_diagnostic_gutter( self, diagnostic_gutter: HashMap<usize, DiagnosticSeverity>, ) -> Self

Source

pub fn with_code_action_lines(self, code_action_lines: HashSet<usize>) -> Self

Source

pub fn with_bracket_match_positions( self, bracket_match_positions: Vec<(usize, usize)>, ) -> Self

Source

pub fn with_active_indent_col(self, active_indent_col: usize) -> Self

Source

pub fn with_tabstop(self, tabstop: usize) -> Self

Source

pub fn with_cursorline(self, cursorline: bool) -> Self

Source

pub fn with_lightbulb_glyph(self, lightbulb_glyph: char) -> Self

Source

pub fn layout( &self, viewport: Rect, cell_width: f32, line_height: f32, ) -> EditorLayout

Compute the viewport geometry for hit-testing and rendering layout.

§Arguments
  • viewport — the rectangle this editor occupies.
  • cell_width — character advance width (1.0 for TUI, font px for GTK).
  • line_height — row height (1.0 for TUI, font px for GTK).

Equivalent to Self::layout_with_options with EditorPaintOptions::default() — kept as a separate, unchanged method (rather than growing this one’s argument list) so every existing caller keeps compiling untouched. See EditorPaintOptions for why a new parameter here would be a breaking change for both known downstream consumers.

Source

pub fn layout_with_options( &self, viewport: Rect, cell_width: f32, line_height: f32, options: EditorPaintOptions, ) -> EditorLayout

Self::layout, plus EditorPaintOptions a host can set to override otherwise-automatic geometry decisions — currently just suppress_v_scrollbar.

Equivalent to Self::layout_with_options_and_v_scrollbar_w with v_scrollbar_w: None (a cell_width-wide scrollbar column).

Source

pub fn layout_with_options_and_v_scrollbar_w( &self, viewport: Rect, cell_width: f32, line_height: f32, options: EditorPaintOptions, v_scrollbar_w: Option<f32>, ) -> EditorLayout

Self::layout_with_options, plus a host-settable vertical scrollbar width in the same pixel units as cell_width / line_height.

Without an override the vertical scrollbar column is exactly cell_width wide — right for TUI’s fixed-cell grid, but on a GUI backend that ties the scrollbar’s width to the font’s glyph advance rather than to a fixed chrome dimension. VS Code’s editor scrollbar is a constant 14px column independent of font size. Some(px) overrides just the scrollbar column’s width (both v_scrollbar_bounds.width and the text-area narrowing it causes) while every other geometry calculation keeps using cell_width. None sizes the column at cell_width. Ignored (there is no column to size) when options.suppress_v_scrollbar is true or the buffer doesn’t overflow the viewport.

GUI hosts normally reach this through crate::Backend::set_editor_v_scrollbar_width rather than calling it directly.

Trait Implementations§

Source§

impl Clone for Editor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Editor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Editor

An editor viewport with no content and every optional/overlay field at its empty default — the new(required…)/with_*/Default trio that lets a consumer build an Editor without an exhaustive struct literal. tabstop defaults to 4 and lightbulb_glyph to '!', matching [default_lightbulb_glyph] and every existing call site’s convention — not derived-Default’s 0 / '\0'.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Editor

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Editor

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Editor

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Editor

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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