pub struct EditorState {
pub content: String,
pub cursors: CursorSet,
pub history: History,
pub config: EditorConfig,
pub version: u64,
pub is_modified: bool,
pub scroll_line: usize,
pub scroll_offset: f32,
pub language: Option<String>,
}editor only.Expand description
The complete state of an editor instance.
Fields§
§content: StringThe document content
cursors: CursorSetCursor positions (supports multi-cursor)
history: HistoryEdit history for undo/redo
config: EditorConfigConfiguration
version: u64Content version (incremented on each change)
is_modified: boolWhether the content has been modified since last save
scroll_line: usizeCurrent scroll position (line number)
scroll_offset: f32Current scroll offset (pixels)
language: Option<String>Detected or explicitly set language
Implementations§
Source§impl EditorState
impl EditorState
Sourcepub fn new(content: impl Into<String>) -> Self
pub fn new(content: impl Into<String>) -> Self
Create a new editor state with the given content.
Sourcepub fn with_config(content: impl Into<String>, config: EditorConfig) -> Self
pub fn with_config(content: impl Into<String>, config: EditorConfig) -> Self
Create with custom configuration.
Sourcepub fn set_content(&mut self, content: impl Into<String>)
pub fn set_content(&mut self, content: impl Into<String>)
Set new content.
Sourcepub fn replace_content(&mut self, content: impl Into<String>)
pub fn replace_content(&mut self, content: impl Into<String>)
Replace content without adding to history (for external updates).
Sourcepub fn cursor_position(&self) -> CursorPosition
pub fn cursor_position(&self) -> CursorPosition
Get the primary cursor position.
Sourcepub fn set_cursor(&mut self, position: CursorPosition)
pub fn set_cursor(&mut self, position: CursorPosition)
Set the primary cursor position.
Sourcepub fn set_cursor_with_selection(
&mut self,
head: CursorPosition,
anchor: CursorPosition,
)
pub fn set_cursor_with_selection( &mut self, head: CursorPosition, anchor: CursorPosition, )
Set the cursor with selection.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get the line count.
Sourcepub fn delete_backward(&mut self)
pub fn delete_backward(&mut self)
Delete the character before the cursor (backspace).
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Delete the character after the cursor (delete).
Sourcepub fn mark_saved(&mut self)
pub fn mark_saved(&mut self)
Mark the content as saved (clears modified flag).
Sourcepub fn position_to_offset(&self, position: CursorPosition) -> Option<usize>
pub fn position_to_offset(&self, position: CursorPosition) -> Option<usize>
Convert a cursor position to a byte offset.
Sourcepub fn offset_to_position(&self, offset: usize) -> Option<CursorPosition>
pub fn offset_to_position(&self, offset: usize) -> Option<CursorPosition>
Convert a byte offset to a cursor position.
Trait Implementations§
Source§impl Clone for EditorState
impl Clone for EditorState
Source§fn clone(&self) -> EditorState
fn clone(&self) -> EditorState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EditorState
impl Debug for EditorState
Auto Trait Implementations§
impl Freeze for EditorState
impl RefUnwindSafe for EditorState
impl Send for EditorState
impl Sync for EditorState
impl Unpin for EditorState
impl UnwindSafe for EditorState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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