Class EditorDocument
The plain text backing store shared by the pure Codename One editors. The document keeps the full text in a single buffer addressed by a linear UTF-16 offset space and derives a cached line index (the start offset of every logical line) on demand for rendering and hit testing.
A single buffer keeps offset arithmetic trivial (offsets are direct buffer indices) which is exactly what the caret, selection, undo stack and the platform text input source all operate on. Line oriented feature layers (syntax highlighting, the gutter) sit on top of the line index.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty document.EditorDocument(String text) Creates a document initialized with the supplied text. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int offset) Returns the character at the given offset.intclamp(int offset) Clamps an arbitrary offset into the valid range[0, length()].intcolumnOfOffset(int offset) Returns the column (offset within its line) for the given absolute offset.voiddelete(int start, int end) Deletes the range[start, end).intReturns the number of logical lines (always at least one).intgetLineEnd(int line) Returns the end offset (exclusive, not counting the trailing newline) of the given line.intgetLineStart(int line) Returns the start offset of the given line.getLineText(int line) Returns the text of the given line without its trailing newline.getText()Returns the full document text.voidInserts text at the given offset.intlength()Returns the total number of UTF-16 characters in the document.intlineOfOffset(int offset) Returns the zero based line index containing the given offset.static StringnormalizeText(String text) Normalizes platform line endings into the document's canonical LF representation.voidReplaces the entire document content.substring(int start, int end) Returns the substring in[start, end).
-
Constructor Details
-
EditorDocument
public EditorDocument()Creates an empty document. -
EditorDocument
Creates a document initialized with the supplied text.
Parameters
text: the initial text, or null for an empty document
-
-
Method Details
-
normalizeText
-
length
public int length()Returns the total number of UTF-16 characters in the document. -
getText
Returns the full document text. -
charAt
public char charAt(int offset) Returns the character at the given offset.
Parameters
offset: a valid offset in[0, length())
-
substring
Returns the substring in[start, end). -
setText
Replaces the entire document content.
Parameters
text: the new text, or null to clear the document
-
insert
Inserts text at the given offset.
Parameters
-
offset: the insertion offset in[0, length()] -
text: the text to insert
-
-
delete
public void delete(int start, int end) Deletes the range
[start, end).Parameters
-
start: inclusive start offset -
end: exclusive end offset
-
-
clamp
public int clamp(int offset) Clamps an arbitrary offset into the valid range[0, length()]. -
getLineCount
public int getLineCount()Returns the number of logical lines (always at least one). -
getLineStart
public int getLineStart(int line) Returns the start offset of the given line.
Parameters
line: a zero based line index in[0, getLineCount())
-
getLineEnd
public int getLineEnd(int line) Returns the end offset (exclusive, not counting the trailing newline) of the given line.
Parameters
line: a zero based line index in[0, getLineCount())
-
getLineText
Returns the text of the given line without its trailing newline.
Parameters
line: a zero based line index in[0, getLineCount())
-
lineOfOffset
public int lineOfOffset(int offset) Returns the zero based line index containing the given offset.
Parameters
offset: an offset in[0, length()]
-
columnOfOffset
public int columnOfOffset(int offset) Returns the column (offset within its line) for the given absolute offset.
Parameters
offset: an offset in[0, length()]
-