Skip to main content

Module edit

Module edit 

Source
Expand description

Changing the text of a paragraph, and what an edit may refuse.

A paragraph’s text is not one string in the tree. It is text nodes, inside spans and links and marks, with text:s, text:tab and text:line-break standing for the whitespace ODF will not write literally, and with elements that contribute no characters at all — a bookmark, a frame, a note, a field — sitting between them. An editor works on the flat string and this module maps the edit back: characters are deleted from the nodes that hold them, new text goes into the node at the insertion point, and every zero-length element stays where it was. DESIGN.md §11.

The string the editor sees, text, is built from the tree and not from the renderer’s layout, because the two differ: the renderer draws a tab as four spaces and a footnote as its citation. Here a tab is a tab, and a footnote contributes nothing and is kept.

Enums§

Mark
Formatting a range of text is given or has taken off.
Refused
Why an edit was not made. Each is a state of the document rather than a failure, and the window says which.

Functions§

apply
Replace the paragraph at a path under a root with what the editor hands back, which may be several paragraphs. Answers how many now stand there.
format
Give a range of the text of the paragraph at a path under the content root a mark, or take it off, writing into the root’s automatic styles whatever style that needs and telling styles of it.
holds_text
Whether an element inside a paragraph holds characters of the paragraph’s text, as a span or a link does, rather than being a mark or a field that contributes none of its own.
is_paragraph
Whether an element is a paragraph or a heading: what an editor edits.
join
Join a paragraph onto the end of another. The first keeps its style; the second’s contents, markers included, follow the first’s.
join_with_previous
Join the paragraph at a path onto the paragraph before it among its parent’s children, and answer where the joined paragraph is.
marked
Whether the characters of a range carry a mark: Some when all of them say the same, None when they differ. A range of no characters answers for the character before it, or after it at the paragraph’s start, which is the one text typed there takes its formatting from; a paragraph with no characters answers for itself.
replace
Replace a range of the paragraph’s text, in characters, with new text.
replace_range
Replace the text from one position to another with new text, and join what is left of the last paragraph onto the first. A position is a paragraph’s path under the root and a character offset into its text.
rewrite
What a paragraph becomes when its whole text is replaced by what an editor hands back: one paragraph, or several where the new text holds newlines the old one did not.
split
Split a paragraph at a character offset into the paragraph before it and the paragraph after, each with the original’s style and attributes.
split_at
Split the paragraph at a path under a root at a character offset, the second half becoming the paragraph after it, and answer where the second half is.
text
The paragraph’s text as an editor sees it: every character the tree holds, in order, with ODF’s whitespace elements as the characters they stand for.