pub trait Document: DocumentPhantom + Any {
// Required methods
fn text(&self) -> Rope;
fn cache_rev(&self) -> RwSignal<u64>;
fn preedit(&self) -> PreeditData;
fn run_command(
&self,
ed: &Editor,
cmd: &Command,
count: Option<usize>,
modifiers: Modifiers,
) -> CommandExecuted;
fn receive_char(&self, ed: &Editor, c: &str);
fn edit(
&self,
iter: &mut dyn Iterator<Item = (Selection, &str)>,
edit_type: EditType,
);
// Provided methods
fn rope_text(&self) -> RopeTextVal { ... }
fn find_unmatched(&self, offset: usize, previous: bool, ch: char) -> usize { ... }
fn find_matching_pair(&self, offset: usize) -> usize { ... }
fn preedit_phantom(
&self,
under_line: Option<Color>,
line: usize,
) -> Option<PhantomText> { ... }
fn compute_screen_lines(
&self,
editor: &Editor,
base: RwSignal<ScreenLinesBase>,
) -> ScreenLines { ... }
fn edit_single(
&self,
selection: Selection,
content: &str,
edit_type: EditType,
) { ... }
}Expand description
A document. This holds text.
Required Methods§
Sourcefn text(&self) -> Rope
fn text(&self) -> Rope
Get the text of the document
Note: typically you should call Document::rope_text as that provides more checks and
utility functions.
fn cache_rev(&self) -> RwSignal<u64>
fn preedit(&self) -> PreeditData
Sourcefn run_command(
&self,
ed: &Editor,
cmd: &Command,
count: Option<usize>,
modifiers: Modifiers,
) -> CommandExecuted
fn run_command( &self, ed: &Editor, cmd: &Command, count: Option<usize>, modifiers: Modifiers, ) -> CommandExecuted
Run a command on the document.
The ed will contain this document (at some level, if it was wrapped then it may not be
directly Rc<Self>)
fn receive_char(&self, ed: &Editor, c: &str)
Sourcefn edit(
&self,
iter: &mut dyn Iterator<Item = (Selection, &str)>,
edit_type: EditType,
)
fn edit( &self, iter: &mut dyn Iterator<Item = (Selection, &str)>, edit_type: EditType, )
Perform the edit(s) on this document.
This intentionally does not require an Editor as this is primarily intended for use by
code that wants to modify the document from ‘outside’ the usual keybinding/command logic.
let editor: TextEditor = text_editor();
let doc: Rc<dyn Document> = editor.doc();
stack((
editor,
button(|| "Append 'Hello'").on_click_stop(move |_| {
let text = doc.text();
doc.edit_single(Selection::caret(text.len()), "Hello", EditType::InsertChars);
})
))Provided Methods§
fn rope_text(&self) -> RopeTextVal
Sourcefn find_unmatched(&self, offset: usize, previous: bool, ch: char) -> usize
fn find_unmatched(&self, offset: usize, previous: bool, ch: char) -> usize
Find the next/previous offset of the match of the given character.
This is intended for use by the Movement::NextUnmatched and
Movement::PreviousUnmatched commands.
Sourcefn find_matching_pair(&self, offset: usize) -> usize
fn find_matching_pair(&self, offset: usize) -> usize
Find the offset of the matching pair character.
This is intended for use by the Movement::MatchPairs command.
fn preedit_phantom( &self, under_line: Option<Color>, line: usize, ) -> Option<PhantomText>
Sourcefn compute_screen_lines(
&self,
editor: &Editor,
base: RwSignal<ScreenLinesBase>,
) -> ScreenLines
fn compute_screen_lines( &self, editor: &Editor, base: RwSignal<ScreenLinesBase>, ) -> ScreenLines
Compute the visible screen lines.
Note: you should typically not need to implement this, unless you have some custom
behavior. Unfortunately this needs an &self to be a trait object. So don’t call .update
on Self
Sourcefn edit_single(&self, selection: Selection, content: &str, edit_type: EditType)
fn edit_single(&self, selection: Selection, content: &str, edit_type: EditType)
Perform a single edit.