JFLib

ui/code_long.rs#

Source: lib/ui/code_long.rs

code_long -- what ui.code_editor (code_edit.rs) keeps of the long lines it shows: checkpoints
of their columns and their tokens, so that a pass looks at the part of a line in view and an
edit works again only near it

  Longs::col / byte / floor     columns (code_doc.rs: col_from, byte_from, cell_floor) from
                                the checkpoint before the place
  Longs::tokens                 the tokens of a long line (highlight.rs) and its end state

A line of COL_LONG bytes or more gets checkpoints (byte, column) at cluster boundaries about
every COL_STEP bytes and keeps its tokens with places outside every construct about every
TOK_STEP bytes.  The entries follow the document's change journal (lines that moved keep
theirs); a line changed in place keeps its text of before, and the next look at it compares:
the columns are walked again from the checkpoint before the change to where they meet the
old ones again (moved along after that, a tab evens out a shift of the columns), the tokens
are scanned again from a place TOK_REACH bytes before the change (rules look ahead) to the
first place after it where the scan is where the old scan was.  A construct that looks
further ahead than TOK_REACH (Markdown emphasis waiting for its closer) is seen again when the
whole line is scanned: a change of its start state, another grammar.
  • fn code_long_check(text: &str, h: &Highlighter, tw: u8, edits: &[(usize, usize, &str)]) -> Vec<String> (tests) line text changed by edits one after the other (bytes a..b of the line then replaced by s): the column checkpoints and the tokens a code editor keeps of a long line, brought along through each change, against a fresh look at the line -> what differs (empty: nothing)

Source: docs/API.md in the JFLib repository.