Skip to main content

CodeDoc

Struct CodeDoc 

Source
pub struct CodeDoc {
    pub tab_width: u8,
    pub use_tabs: bool,
    /* private fields */
}
Expand description

the document of ui.code_editor (see the module header)

Fields§

§tab_width: u8

columns between tab stops (1..16)

§use_tabs: bool

indent with tabs (else with blanks)

Implementations§

Source§

impl CodeDoc

Source

pub fn new() -> CodeDoc

one empty line

Source

pub fn from_text(s: &str) -> CodeDoc

a text: a line per ‘\n’ (‘\r\n’ and ‘\r’ too)

Source

pub fn from_lines(lines: Vec<String>) -> CodeDoc

lines (an empty list: one empty line); they must not hold ‘\n’

Source

pub fn text(&self) -> String

the text: the lines joined by ‘\n’

Source

pub fn line_count(&self) -> usize

the number of lines (at least 1)

Source

pub fn line(&self, i: usize) -> &str

line i (clamped to the last one), without its ‘\n’

Source

pub fn lines(&self) -> &[String]

every line

Source

pub fn revision(&self) -> u64

counts the content changes (edits, undo, redo)

Source

pub fn changes_since(&self, rev: u64) -> Option<&[LineChange]>

the changes after revision rev, oldest first (None: the journal no longer reaches back that far – start again)

Source

pub fn selection(&self) -> TextSel

the selection (the caret: anchor == caret)

Source

pub fn set_selection(&mut self, sel: TextSel)

move the selection (clamped, not undoable)

Source

pub fn clamp(&self, p: TextPos) -> TextPos

p inside the document, on a character boundary

Source

pub fn end(&self) -> TextPos

the end of the document

Source

pub fn text_range(&self, a: TextPos, b: TextPos) -> String

the text between a and b

Source

pub fn selected_text(&self) -> String

the selected text (lines joined by ‘\n’)

Source

pub fn flat(&self, p: TextPos) -> usize

the byte offset of p in text()

Source

pub fn unflat(&self, f: usize) -> TextPos

the position of byte offset f of text()

Source

pub fn col_of(&self, line: usize, byte: usize) -> usize

the visual column of byte in a line (tabs to the next stop, wide characters 2)

Source

pub fn byte_at_col(&self, line: usize, col: usize) -> usize

the byte of the cluster boundary nearest to column col

Source

pub fn can_undo(&self) -> bool

there is a step to undo

Source

pub fn can_redo(&self) -> bool

there is a step to redo

Source

pub fn undo_label(&self) -> Option<&str>

the label of the step undo takes back

Source

pub fn redo_label(&self) -> Option<&str>

the label of the step redo does again

Source

pub fn undo(&mut self) -> bool

take the last step back -> false: nothing to undo

Source

pub fn redo(&mut self) -> bool

do the last undone step again -> false: nothing to redo

Source

pub fn is_dirty(&self) -> bool

the content differs from the state of the last mark_saved

Source

pub fn mark_saved(&mut self)

the content is saved now

Source

pub fn clear_history(&mut self)

forget the undo steps

Source

pub fn replace(&mut self, a: TextPos, b: TextPos, s: &str) -> TextPos

replace a..b by s; the caret after it -> the end of s

Source

pub fn insert(&mut self, s: &str) -> TextPos

replace the selection by s (a paste)

Source

pub fn delete(&mut self, a: TextPos, b: TextPos) -> bool

remove a..b

Source

pub fn indentation(&self, line: usize) -> &str

the leading blanks of a line

Source

pub fn indent_unit(&self) -> String

one level of indentation (a tab or tab_width blanks)

Source

pub fn type_text(&mut self, s: &str, closers: &str) -> bool

typed text replaces the selection; a closer of closers typed as the first character of a blank line takes one level of indentation away

Source

pub fn newline(&mut self, openers: &str) -> bool

Enter: a line break with the line’s indentation; after an opener of openers (the last non-blank character before the caret) one level more, and when its closer follows the caret, that goes to a line of its own

Source

pub fn tab(&mut self) -> bool

Tab: the selected lines one level in (several lines selected), else the indentation up to the next tab stop at the caret (replacing the selection)

Source

pub fn back_tab(&mut self) -> bool

Shift+Tab: the selected lines (or the caret’s) one level out

Source

pub fn indent(&mut self, delta: i32) -> bool

the selected lines (a selection ending at a line start leaves that line out) one level in (delta > 0) or out; the selection follows its text

Source

pub fn toggle_comment(&mut self, prefix: &str) -> bool

line comments on (when not every selected non-blank line has one) or off

Source

pub fn move_lines(&mut self, delta: i32) -> bool

Alt+Up / Alt+Down: the selected lines move one line up (delta < 0) or down

Source

pub fn find_all(&self, q: &str, opts: u8) -> Vec<(TextPos, TextPos)>

every match of q (FIND_CASE, FIND_WORD), at most FIND_MAX

Source

pub fn find_lines( &self, q: &str, opts: u8, first: usize, n: usize, ) -> Vec<(TextPos, TextPos)>

the matches of q in lines first .. first + n

Source

pub fn find_next( &self, from: TextPos, q: &str, opts: u8, backwards: bool, ) -> Option<(TextPos, TextPos)>

the next match after from (backwards: the last one before it), wrapping around

Source

pub fn sel_is_match(&self, q: &str, opts: u8) -> bool

the selection is a match of q

Source

pub fn replace_next(&mut self, q: &str, rep: &str, opts: u8) -> bool

replace the selection when it is a match, then select the next match -> replaced

Source

pub fn replace_all(&mut self, q: &str, rep: &str, opts: u8) -> usize

replace every match (one undo step) -> how many

Source

pub fn set_diagnostics(&mut self, d: &[Diag])

replace the diagnostics (Diag positions, clamped to the text); from now on they follow the edits until the next call (see the module header)

Source

pub fn clear_diagnostics(&mut self)

no diagnostics

Source

pub fn diagnostics(&self) -> Vec<Diag>

the diagnostics where they are now, by position

Source

pub fn diagnostic_count(&self) -> usize

the number of diagnostics

Source

pub fn diagnostic(&self, i: usize) -> Option<Diag>

diagnostic i (0 .. diagnostic_count(), by position) where it is now

Source

pub fn diagnostic_counts(&self) -> [usize; 3]

the number of errors, warnings and infos (DIAG_* order)

Source

pub fn diagnostics_at(&self, p: TextPos) -> Vec<Diag>

the diagnostics at p (their part holds p, its end included; a point: its character), most severe first

Source

pub fn next_diagnostic(&self, p: TextPos, back: bool) -> Option<TextPos>

the start of the first diagnostic after p (back: the last one before p), round the end of the text; None without diagnostics

Source

pub fn set_breakpoints(&mut self, bps: &[(usize, u8)])

the breakpoints: (line from 0, BP_*), drawn in the gutter column of CE_BREAKPOINTS (the app keeps the real ones: a click there is CodeEv::Breakpoint); they follow the edits with their lines until the next call

Source

pub fn breakpoints(&self) -> &[(usize, u8)]

the breakpoints where they are now, by line

Source

pub fn breakpoint(&self, line: usize) -> Option<u8>

the breakpoint of a line

Source

pub fn set_exec_line(&mut self, line: Option<usize>)

the line a debugger stopped at (None: none), drawn marked with an arrow in the breakpoints’ column; it follows the edits

Source

pub fn exec_line(&self) -> Option<usize>

the line of set_exec_line where it is now

Source

pub fn set_fold_ranges(&mut self, ranges: &[(usize, usize)])

the folding ranges (first, last) with lines from 0 (a language’s services give them): line first stays, first + 1 ..= last fold away. A range that starts on the line of a folded one stays folded; ranges follow the edits, and an edit inside the hidden lines of a folded range unfolds it

Source

pub fn fold_count(&self) -> usize

the number of folding ranges

Source

pub fn fold_ranges(&self) -> Vec<(usize, usize, bool)>

the folding ranges where they are now: (first, last, folded)

Source

pub fn fold_at(&self, line: usize) -> Option<(usize, bool)>

the range that starts at line: (last, folded)

Source

pub fn set_folded(&mut self, line: usize, folded: bool) -> bool

fold (folded) or unfold the range that starts at line -> changed

Source

pub fn toggle_fold(&mut self, line: usize) -> bool

fold or unfold the range that starts at line -> changed

Source

pub fn fold_all(&mut self, folded: bool)

every range folded (true) or unfolded

Source

pub fn fold_around(&self, line: usize) -> Option<(usize, usize)>

the innermost range that holds line (its first line counts): (first, last)

Source

pub fn is_hidden(&self, line: usize) -> bool

line is hidden in a folded range

Source

pub fn reveal(&mut self, line: usize) -> bool

unfold every range that hides line -> changed

Source

pub fn visible_lines(&self) -> usize

the lines that are not hidden

Source

pub fn row_of_line(&self, line: usize) -> usize

the visible row of a line (counting only lines that are not hidden; a hidden line: the row of its fold’s first line)

Source

pub fn line_of_row(&self, row: usize) -> usize

the line of a visible row

Source

pub fn visible_line(&self, line: usize, down: bool) -> usize

the nearest line that is not hidden from line on, downwards (down) or upwards

Source

pub fn apply_edits(&mut self, edits: &[TextEdit], label: &str) -> bool

several changes as one undo step named label: the edits (positions in the text before any of them, in any order, not overlapping) replace their parts; the selection follows the text (inside a replaced part: to its new end) -> false when nothing changed or two edits overlap. Rename and format of a language service go through here

Source

pub fn replace_text(&mut self, text: &str, label: &str) -> bool

the whole text becomes text as one undo step; only the lines that differ change (the diagnostics, breakpoints and folds of the others stay), and the caret keeps its place among the characters that are no blanks (so after a formatter it stays at its token) -> changed

Trait Implementations§

Source§

impl Default for CodeDoc

Source§

fn default() -> CodeDoc

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

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.