Struct Document
pub struct Document {
pub id: DocumentId,
pub path: Option<PathBuf>,
pub source: DocumentSource,
pub language: EditorLanguage,
pub version: DocumentVersion,
pub dirty: bool,
pub buffer: TextBuffer,
}Expand description
Open document metadata plus rope-backed text.
Fields are public for controlled editor composition. Changing buffer
directly does not increment version or set dirty; session methods should
mediate edits when those invariants matter.
§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentVersion, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::from_string("hello"));
assert_eq!(document.version, DocumentVersion(0));
assert_eq!(document.language, EditorLanguage::PlainText);
assert!(!document.dirty);Fields§
§id: DocumentIdStable session-local document identity.
path: Option<PathBuf>Optional local path retained for compatibility and language detection.
source: DocumentSourceCanonical memory/path/URI origin description.
language: EditorLanguageExplicit or detected language.
version: DocumentVersionContent revision; initialized to zero.
dirty: boolWhether content differs from its externally saved version.
buffer: TextBufferRope-backed UTF-8 content.
Implementations§
§impl Document
Document construction and language-hint operations.
impl Document
Document construction and language-hint operations.
pub fn new(id: DocumentId, buffer: TextBuffer) -> Document
pub fn new(id: DocumentId, buffer: TextBuffer) -> Document
Creates a clean, version-zero in-memory plain-text document.
§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(2), TextBuffer::new());
assert_eq!(document.source, DocumentSource::Memory);
assert!(document.path.is_none());pub fn with_path(self, path: impl Into<PathBuf>) -> Document
pub fn with_path(self, path: impl Into<PathBuf>) -> Document
Sets both path and DocumentSource::LocalPath without detection.
§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_path("src/main.rs");
assert!(matches!(document.source, DocumentSource::LocalPath(_)));
assert_eq!(document.path.unwrap().to_str(), Some("src/main.rs"));pub fn with_source(self, source: DocumentSource) -> Document
pub fn with_source(self, source: DocumentSource) -> Document
Replaces the origin and synchronizes the optional local path.
Memory preserves an existing legacy path, a local file URI converts
to a host path when possible, and non-file URIs clear path.
§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_fs::FileUri;
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new())
.with_source(DocumentSource::Uri(FileUri::parse("sftp://host/main.rs")?));
assert!(document.path.is_none());pub fn with_uri(self, uri: FileUri) -> Document
pub fn with_uri(self, uri: FileUri) -> Document
Convenience wrapper for Self::with_source with a URI origin.
§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_fs::FileUri;
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_uri(FileUri::parse("sftp://host/doc")?);
assert!(matches!(document.source, DocumentSource::Uri(_)));pub fn with_language(self, language: EditorLanguage) -> Document
pub fn with_language(self, language: EditorLanguage) -> Document
Replaces the language without inspecting the path or buffer.
§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_language(EditorLanguage::Rust);
assert_eq!(document.language, EditorLanguage::Rust);pub fn detect_language(&mut self)
pub fn detect_language(&mut self)
Replaces the current language with extension-based detection.
With no hint this selects PlainText; an unrecognized extension selects
Unknown, even if a different explicit language was previously set.
§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let mut document = Document::new(DocumentId(1), TextBuffer::new()).with_path("lib.rs");
document.detect_language();
assert_eq!(document.language, EditorLanguage::Rust);pub fn language_path_hint(&self) -> Option<&Path>
pub fn language_path_hint(&self) -> Option<&Path>
Returns path first, then the source-derived hint.
§Examples
use std::path::Path;
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_path("main.rs");
assert_eq!(document.language_path_hint(), Some(Path::new("main.rs")));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.