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: u8columns between tab stops (1..16)
use_tabs: boolindent with tabs (else with blanks)
Implementations§
Source§impl CodeDoc
impl CodeDoc
Sourcepub fn from_lines(lines: Vec<String>) -> CodeDoc
pub fn from_lines(lines: Vec<String>) -> CodeDoc
lines (an empty list: one empty line); they must not hold ‘\n’
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
the number of lines (at least 1)
Sourcepub fn changes_since(&self, rev: u64) -> Option<&[LineChange]>
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)
Sourcepub fn set_selection(&mut self, sel: TextSel)
pub fn set_selection(&mut self, sel: TextSel)
move the selection (clamped, not undoable)
Sourcepub fn text_range(&self, a: TextPos, b: TextPos) -> String
pub fn text_range(&self, a: TextPos, b: TextPos) -> String
the text between a and b
Sourcepub fn selected_text(&self) -> String
pub fn selected_text(&self) -> String
the selected text (lines joined by ‘\n’)
Sourcepub fn col_of(&self, line: usize, byte: usize) -> usize
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)
Sourcepub fn byte_at_col(&self, line: usize, col: usize) -> usize
pub fn byte_at_col(&self, line: usize, col: usize) -> usize
the byte of the cluster boundary nearest to column col
Sourcepub fn undo_label(&self) -> Option<&str>
pub fn undo_label(&self) -> Option<&str>
the label of the step undo takes back
Sourcepub fn redo_label(&self) -> Option<&str>
pub fn redo_label(&self) -> Option<&str>
the label of the step redo does again
Sourcepub fn mark_saved(&mut self)
pub fn mark_saved(&mut self)
the content is saved now
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
forget the undo steps
Sourcepub fn replace(&mut self, a: TextPos, b: TextPos, s: &str) -> TextPos
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
Sourcepub fn indentation(&self, line: usize) -> &str
pub fn indentation(&self, line: usize) -> &str
the leading blanks of a line
Sourcepub fn indent_unit(&self) -> String
pub fn indent_unit(&self) -> String
one level of indentation (a tab or tab_width blanks)
Sourcepub fn type_text(&mut self, s: &str, closers: &str) -> bool
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
Sourcepub fn newline(&mut self, openers: &str) -> bool
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
Sourcepub fn tab(&mut self) -> bool
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)
Sourcepub fn back_tab(&mut self) -> bool
pub fn back_tab(&mut self) -> bool
Shift+Tab: the selected lines (or the caret’s) one level out
Sourcepub fn indent(&mut self, delta: i32) -> bool
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
Sourcepub fn toggle_comment(&mut self, prefix: &str) -> bool
pub fn toggle_comment(&mut self, prefix: &str) -> bool
line comments on (when not every selected non-blank line has one) or off
Sourcepub fn move_lines(&mut self, delta: i32) -> bool
pub fn move_lines(&mut self, delta: i32) -> bool
Alt+Up / Alt+Down: the selected lines move one line up (delta < 0) or down
Sourcepub fn find_all(&self, q: &str, opts: u8) -> Vec<(TextPos, TextPos)>
pub fn find_all(&self, q: &str, opts: u8) -> Vec<(TextPos, TextPos)>
every match of q (FIND_CASE, FIND_WORD), at most FIND_MAX
Sourcepub fn find_lines(
&self,
q: &str,
opts: u8,
first: usize,
n: usize,
) -> Vec<(TextPos, TextPos)>
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
Sourcepub fn find_next(
&self,
from: TextPos,
q: &str,
opts: u8,
backwards: bool,
) -> Option<(TextPos, TextPos)>
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
Sourcepub fn sel_is_match(&self, q: &str, opts: u8) -> bool
pub fn sel_is_match(&self, q: &str, opts: u8) -> bool
the selection is a match of q
Sourcepub fn replace_next(&mut self, q: &str, rep: &str, opts: u8) -> bool
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
Sourcepub fn replace_all(&mut self, q: &str, rep: &str, opts: u8) -> usize
pub fn replace_all(&mut self, q: &str, rep: &str, opts: u8) -> usize
replace every match (one undo step) -> how many
Sourcepub fn set_diagnostics(&mut self, d: &[Diag])
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)
Sourcepub fn clear_diagnostics(&mut self)
pub fn clear_diagnostics(&mut self)
no diagnostics
Sourcepub fn diagnostics(&self) -> Vec<Diag>
pub fn diagnostics(&self) -> Vec<Diag>
the diagnostics where they are now, by position
Sourcepub fn diagnostic_count(&self) -> usize
pub fn diagnostic_count(&self) -> usize
the number of diagnostics
Sourcepub fn diagnostic(&self, i: usize) -> Option<Diag>
pub fn diagnostic(&self, i: usize) -> Option<Diag>
diagnostic i (0 .. diagnostic_count(), by position) where it is now
Sourcepub fn diagnostic_counts(&self) -> [usize; 3]
pub fn diagnostic_counts(&self) -> [usize; 3]
the number of errors, warnings and infos (DIAG_* order)
Sourcepub fn diagnostics_at(&self, p: TextPos) -> Vec<Diag>
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
Sourcepub fn next_diagnostic(&self, p: TextPos, back: bool) -> Option<TextPos>
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
Sourcepub fn set_breakpoints(&mut self, bps: &[(usize, u8)])
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
Sourcepub fn breakpoints(&self) -> &[(usize, u8)]
pub fn breakpoints(&self) -> &[(usize, u8)]
the breakpoints where they are now, by line
Sourcepub fn breakpoint(&self, line: usize) -> Option<u8>
pub fn breakpoint(&self, line: usize) -> Option<u8>
the breakpoint of a line
Sourcepub fn set_exec_line(&mut self, line: Option<usize>)
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
Sourcepub fn set_fold_ranges(&mut self, ranges: &[(usize, usize)])
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
Sourcepub fn fold_count(&self) -> usize
pub fn fold_count(&self) -> usize
the number of folding ranges
Sourcepub fn fold_ranges(&self) -> Vec<(usize, usize, bool)>
pub fn fold_ranges(&self) -> Vec<(usize, usize, bool)>
the folding ranges where they are now: (first, last, folded)
Sourcepub fn fold_at(&self, line: usize) -> Option<(usize, bool)>
pub fn fold_at(&self, line: usize) -> Option<(usize, bool)>
the range that starts at line: (last, folded)
Sourcepub fn set_folded(&mut self, line: usize, folded: bool) -> bool
pub fn set_folded(&mut self, line: usize, folded: bool) -> bool
fold (folded) or unfold the range that starts at line -> changed
Sourcepub fn toggle_fold(&mut self, line: usize) -> bool
pub fn toggle_fold(&mut self, line: usize) -> bool
fold or unfold the range that starts at line -> changed
Sourcepub fn fold_around(&self, line: usize) -> Option<(usize, usize)>
pub fn fold_around(&self, line: usize) -> Option<(usize, usize)>
the innermost range that holds line (its first line counts): (first, last)
line is hidden in a folded range
Sourcepub fn visible_lines(&self) -> usize
pub fn visible_lines(&self) -> usize
the lines that are not hidden
Sourcepub fn row_of_line(&self, line: usize) -> usize
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)
Sourcepub fn line_of_row(&self, row: usize) -> usize
pub fn line_of_row(&self, row: usize) -> usize
the line of a visible row
Sourcepub fn visible_line(&self, line: usize, down: bool) -> usize
pub fn visible_line(&self, line: usize, down: bool) -> usize
the nearest line that is not hidden from line on, downwards (down) or upwards
Sourcepub fn apply_edits(&mut self, edits: &[TextEdit], label: &str) -> bool
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
Sourcepub fn replace_text(&mut self, text: &str, label: &str) -> bool
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