Doc class
Each editor is associated with an instance of Doc, its document. A document
represents the editor content, plus a selection, an undo history, and a mode.
A document can only be associated with a single editor at a time. You can
create new documents by calling the
CodeMirror.Doc(text, mode, firstLineNumber)
constructor. The last two
arguments are optional and can be used to set a mode for the document and
make it start at a line number other than 0, respectively.
- Inheritance
-
- Object
- ProxyHolder
- Doc
Properties
- editor → CodeMirror
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- jsProxy → JsObject?
-
finalinherited
- onChange → Stream
-
Fired whenever a change occurs to the document.
changeObj
has a similar type as the object passed to the editor's "change" event.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addSelection(
{required Position anchor, Position? head}) → void - Adds a new selection to the existing set of selections, and makes it the primary selection.
-
call(
String methodName) → dynamic -
inherited
-
callArg(
String methodName, dynamic arg) → dynamic -
inherited
-
callArgs(
String methodName, List args) → dynamic -
inherited
-
changeGeneration(
[bool? closeEvent]) → int? - Returns a number that can later be passed to isClean to test whether any edits were made (and not undone) in the meantime. If closeEvent is true, the current history event will be 'closed', meaning it can't be combined with further changes (rapid typing or deleting events are typically combined).
-
clearHistory(
) → void - Clears the editor's undo history.
-
dispose(
) → void -
This method should be called if any events listeners were added to the
object.
inherited
-
eachLine(
LineHandler callback, {int? start, int? end}) → void -
Iterate over the whole document, or if
start
andend
line numbers are given, the range from start up to (not including) end, and call f for each line, passing the line handle. This is a faster way to visit a range of line handlers than calling getLineHandle for each of them. Note that line handles have a text property containing the line's content (as a string). -
extendSelection(
Position from, [Position? to, Map? options]) → void -
Similar to setSelection, but will, if shift is held or the extending flag
is set, move the head of the selection while leaving the anchor at its
current place.
to
is optional, and can be passed to ensure a region (for example a word or paragraph) will end up selected (in addition to whatever lies between that region and the current anchor). When multiple selections are present, all but the primary selection will be dropped by this method. Supports the same options as setSelection. -
extendSelections(
List< Position> heads, [Map? options]) → void - An equivalent of extendSelection that acts on all selections at once.
-
extendSelectionsBy(
SelectionExtender f, [Map? options]) → void - Applies the given function to all existing selections, and calls extendSelections on the result.
-
findMarks(
Position from, Position to) → List< TextMarker> - Returns an array of all the bookmarks and marked ranges found between the given positions.
-
findMarksAt(
Position pos) → List< TextMarker> - Returns an array of all the bookmarks and marked ranges present at the given position.
-
firstLine(
) → int? - Get the first line of the editor. This will usually be zero but for linked sub-views, or documents instantiated with a non-zero first line, it might return other values.
-
getAllMarks(
) → List< TextMarker> - Returns an array containing all marked ranges in the document.
-
getCursor(
[String? start]) → Position - Retrieve one end of the primary selection. start is a an optional string indicating which end of the selection to return. It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow), or "anchor" (the fixed side of the selection). Omitting the argument is the same as passing "head". A {line, ch} object will be returned.
-
getEditor(
) → CodeMirror -
getExtending(
) → bool? - Get the value of the 'extending' flag.
-
getHistory(
) → JsObject? - Get a (JSON-serializable) representation of the undo history.
-
getLine(
int? n) → String? - Get the content of line n.
-
getLineHandle(
int? line) → LineHandle - Fetches the line handle for the given line number.
-
getLineNumber(
LineHandle handle) → int? -
Given a line handle, returns the current position of that line (or
null
when it is no longer in the document). -
getMode(
) → dynamic - Gets the (outer) mode object for the editor. Note that this is distinct from getOption("mode"), which gives you the mode specification, rather than the resolved, instantiated mode object.
-
getModeAt(
Position pos) → dynamic - Gets the inner mode at a given position. This will return the same as getMode for simple modes, but will return an inner mode for nesting modes (such as htmlmixed).
-
getModeName(
) → String? - Return the name of the current mode.
-
getModeNameAt(
Position pos) → String? - Return the name of the mode at the given position.
-
getRange(
Position from, Position to, [String? separator]) → String? - Get the text between the given points in the editor. An optional third argument can be given to indicate the line separator string to use (defaults to "\n").
-
getSelection(
[String? lineSep]) → String? -
Get the currently selected code. Optionally pass a line separator to put
between the lines in the output. When multiple selections are present, they
are concatenated with instances of
lineSep
in between. -
getSelections(
[String? lineSep]) → Iterable< String> - Returns an array containing a string for each selection, representing the content of the selections.
-
getValue(
[String? separator]) → String? - Get the current editor content. You can pass it an optional argument to specify the string to be used to separate lines (defaults to "\n").
-
historySize(
) → Map< String, int?> -
Returns an object with
{'undo': int, 'redo': int}
properties, both of which hold integers, indicating the amount of stored undo and redo operations. -
indexFromPos(
Position pos) → int? - The reverse of posFromIndex.
-
isClean(
[int? generation]) → bool - Returns whether the document is currently clean, not modified since initialization or the last call to markClean if no argument is passed, or since the matching call to changeGeneration if a generation value is given.
-
lastLine(
) → int? - Get the last line of the editor. This will usually be doc.lineCount() - 1, but for linked sub-views, it might return other values.
-
lineCount(
) → int? - Get the number of lines in the editor.
-
listSelections(
) → Iterable< Span> ? - Retrieves a list of all current selections.
-
markClean(
) → void - Set the editor content as 'clean', a flag that it will retain until it is edited, and which will be set again when such an edit is undone again. Useful to track whether the content needs to be saved. This function is deprecated in favor of changeGeneration, which allows multiple subsystems to track different notions of cleanness without interfering.
-
markText(
Position from, Position to, {String? className, bool? inclusiveLeft, bool? inclusiveRight, bool? atomic, bool? collapsed, bool? clearOnEnter, bool? clearWhenEmpty, Element? replacedWith, bool? handleMouseEvents, bool? readOnly, bool? addToHistory, String? startStyle, String? endStyle, String? css, String? title, }) → TextMarker - Can be used to mark a range of text with a specific CSS class name.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onEvent<
T> (String eventName, {int argCount = 1}) → Stream< T?> -
inherited
-
posFromIndex(
int index) → Position -
Calculates and returns a
Position
object for a zero-based index who's value is relative to the start of the editor's text. If the index is out of range of the text then the returned object is clipped to start or end of the text respectively. -
redo(
) → void - Redo one undone edit.
-
redoSelection(
) → void - Redo one undone edit or selection change.
-
replaceRange(
String replacement, Position from, [Position? to, String? origin]) → void -
Replace the part of the document between
from
andto
with the given string.to
can be left off to simply insert the string at positionfrom
. -
replaceSelection(
String replacement, [String? select]) → void -
Replace the selection(s) with the given string. By default, the new
selection ends up after the inserted text. The optional select argument can
be used to change this. Passing
around
: will cause the new text to be selected;start
: will collapse the selection to the start of the inserted text. -
replaceSelections(
Iterable< String> replacement, {String? select}) → void - The length of the given array should be the same as the number of active selections. Replaces the content of the selections with the strings in the array. The select argument works the same as in replaceSelection.
-
setBookmark(
Position pos, {Element? widget, bool? insertLeft, }) → TextMarker - Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position. A bookmark has two methods find() and clear(). The first returns the current position of the bookmark, if it is still in the document, and the second explicitly removes the bookmark.
-
setCursor(
Position pos, {Map? options}) → void - Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters. Will replace all selections with a single, empty selection at the given position. The supported options are the same as for setSelection.
-
setExtending(
bool value) → void - Sets or clears the 'extending' flag, which acts similar to the shift key, in that it will cause cursor movement and calls to extendSelection to leave the selection anchor in place.
-
setHistory(
JsObject history) → void - Replace the editor's undo history with the one provided, which must be a value as returned by getHistory. Note that this will have entirely undefined results if the editor content isn't also the same as it was when getHistory was called.
-
setSelection(
Position anchor, {Position? head, Map? options}) → void - Set a single selection range. anchor and head should be {line, ch} objects. head defaults to anchor when not given. These options are supported:
-
setSelections(
Iterable< Span> ranges, {int? primary, Map? options}) → void -
Sets a new set of selections. There must be at least one selection in the
given array. When
primary
is a number, it determines which selection is the primary one. When it is not given, the primary index is taken from the previous selection, or set to the last range if the previous selection had less ranges than the new one. Supports the same options as setSelection. -
setValue(
String value) → void - Set the editor content.
-
somethingSelected(
) → bool -
Return
true
if any text is selected. -
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → void - Undo one edit (if any undo events are stored).
-
undoSelection(
) → void - Undo one edit or selection change.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited