public final class RichBlocks

  1. Object
  2. RichBlocks
The per paragraph block attribute model for the pure rich text editor. Each logical line (paragraph, delimited by newlines) has a BlockAttr describing its block type (paragraph / heading / preformatted / blockquote), text alignment, list membership and indentation. The model is kept in lockstep with the paragraph structure through #applyEdit.

Nested types

class RichBlocks.BlockAttrA single paragraph’s block attributes.

Fields

public static final int PARAGRAPH = 0Block type: a normal paragraph.
public static final int H1 = 1Block type: heading level 1 through 6 are H1..H1 + 5.
public static final int PRE = 7Block type: preformatted text.
public static final int BLOCKQUOTE = 8Block type: a block quote.
public static final int ALIGN_LEFT = 0Left alignment.
public static final int ALIGN_CENTER = 1Center alignment.
public static final int ALIGN_RIGHT = 2Right alignment.
public static final int LIST_NONE = 0Not a list item.
public static final int LIST_ORDERED = 1An ordered (numbered) list item.
public static final int LIST_UNORDERED = 2An unordered (bulleted) list item.

Constructors

public RichBlocks(int paragraphCount)Creates a model with the given paragraph count, all default paragraphs.

Methods

public void reset(int paragraphCount)Resets the model to the given paragraph count, all default paragraphs.
public int count()Returns the number of paragraphs.
public RichBlocks.BlockAttr get(int paragraph)Returns the block attributes for the given paragraph (clamped to the valid range).
public void applyEdit(int startParagraph, int removedNewlines, int addedNewlines)Keeps the model in sync with a text edit that changed the paragraph structure.

Inherited methods

Field details

PARAGRAPH

public static final int PARAGRAPH = 0
Block type: a normal paragraph.

H1

public static final int H1 = 1
Block type: heading level 1 through 6 are H1..H1 + 5.

PRE

public static final int PRE = 7
Block type: preformatted text.

BLOCKQUOTE

public static final int BLOCKQUOTE = 8
Block type: a block quote.

ALIGN_LEFT

public static final int ALIGN_LEFT = 0
Left alignment.

ALIGN_CENTER

public static final int ALIGN_CENTER = 1
Center alignment.

ALIGN_RIGHT

public static final int ALIGN_RIGHT = 2
Right alignment.

LIST_NONE

public static final int LIST_NONE = 0
Not a list item.

LIST_ORDERED

public static final int LIST_ORDERED = 1
An ordered (numbered) list item.

LIST_UNORDERED

public static final int LIST_UNORDERED = 2
An unordered (bulleted) list item.

Constructor details

RichBlocks

public RichBlocks(int paragraphCount)
Creates a model with the given paragraph count, all default paragraphs.

Method details

reset

public void reset(int paragraphCount)
Resets the model to the given paragraph count, all default paragraphs.

count

public int count()
Returns the number of paragraphs.

get

public RichBlocks.BlockAttr get(int paragraph)
Returns the block attributes for the given paragraph (clamped to the valid range).

applyEdit

public void applyEdit(int startParagraph, int removedNewlines, int addedNewlines)
Keeps the model in sync with a text edit that changed the paragraph structure.

Parameters

startParagraph int
the paragraph containing the edit offset
removedNewlines int
number of newlines in the removed text (paragraphs merged away)
addedNewlines int
number of newlines in the inserted text (paragraphs created)