CodeMirror class
A wrapper around the CodeMirror editor.
- Inheritance
-
- Object
- ProxyHolder
- CodeMirror
Constructors
- CodeMirror.fromElement(Element element, {Map? options})
- Create a new CodeMirror editor in the given element. See http://codemirror.net/doc/manual.html#config for valid options values.
- CodeMirror.fromJsObject(JsObject? object)
-
Create a new CodeMirror editor from the given JsObject. This will return an
existing Dart
CodeMirror
object if there is already one for the given JavaScript proxy.factory - CodeMirror.fromTextArea(TextAreaElement? textArea, {Map? options})
-
The method provides another way to initialize an editor. It takes a
textarea DOM node as first argument and an optional configuration object as
second. It will replace the textarea with a CodeMirror instance, and wire
up the form of that textarea (if any) to make sure the editor contents are
put into the textarea when the form is submitted. The text in the textarea
will provide the content for the editor. A CodeMirror instance created this
way has three additional methods:
save
,toTextArea
, andgetTextArea
.
Properties
- doc → Doc
-
Retrieve the currently active document from an editor.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- jsProxy → JsObject?
-
finalinherited
- onChange → Stream
-
Fires every time the content of the editor is changed.
no setter
- onCursorActivity → Stream
-
Will be fired when the cursor or selection moves, or any change is made to
the editor content.
no setter
-
onDoubleClick
→ Stream<
MouseEvent> -
Fired when a mouse is double-clicked. You can preventDefault the event to
signal that CodeMirror should do no further handling.
no setter
-
onGutterClick
→ Stream<
int?> -
Fires when the editor gutter (the line-number area) is clicked.
no setter
-
onMouseDown
→ Stream<
MouseEvent> -
Fired when a mouse is clicked. You can preventDefault the event to signal
that CodeMirror should do no further handling.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addLineClass(
dynamic line, String where, String cssClass) → LineHandle -
Set a CSS class name for the given line.
line
can be a number or a LineHandle.where
determines to which element this class should be applied, can can be one of "text" (the text element, which lies in front of the selection), "background" (a background element that will be behind the selection), "gutter" (the line's gutter space), or "wrap" (the wrapper node that wraps all of the line's elements, including gutter elements).cssClass
should be the name of the class to apply. -
addLineWidget(
dynamic line, Element node, {bool? coverGutter, bool? noHScroll, bool? above, bool? handleMouseEvents, int? insertAt, String? className}) → LineWidget -
Adds a line widget, an element shown below a line, spanning the whole of
the editor's width, and moving the lines below it downwards.
line
should be either an integer or a LineHandle, and node should be a DOM node, which will be displayed below the given line. -
addWidget(
Position pos, Element node, [bool scrollIntoView = false]) → void - Puts node, which should be an absolutely positioned DOM node, into the editor, positioned right below the given {line, ch} position. When scrollIntoView is true, the editor will ensure that the entire node is visible (if possible). To remove the widget again, simply use DOM methods (move it somewhere else, or call removeChild on its parent).
-
call(
String methodName) → dynamic -
inherited
-
callArg(
String methodName, dynamic arg) → dynamic -
inherited
-
callArgs(
String methodName, List args) → dynamic -
inherited
-
clearGutter(
String gutterID) → void - Remove all gutter markers in the gutter with the given ID.
-
dispose(
) → void -
If you create and discard a large number of
CodeMirror
instances, you should call dispose after finishing with each one.override -
execCommand(
String name) → void - Runs the command with the given name on the editor.
-
focus(
) → void - Give the editor focus.
-
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. -
getDoc(
) → Doc - Retrieve the currently active document from an editor.
-
getHelper(
Position pos, String type) → JsObject? - Returns the first applicable helper value.
-
getHelpers(
Position pos, String type) → List< JsObject> - Fetch the set of applicable helper values for the given position. Helpers provide a way to look up functionality appropriate for a mode. The type argument provides the helper namespace (see registerHelper), in which the values will be looked up. When the mode itself has a property that corresponds to the type, that directly determines the keys that are used to look up the helper values (it may be either a single string, or an array of strings). Failing that, the mode's helperType property and finally the mode's name are used.
-
getIndentUnit(
) → int? - How many spaces a block (whatever that means in the edited language) should be indented. The default is 2.
-
getIndentWithTabs(
) → bool - Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. Default is false.
-
getInputField(
) → Element? - Returns the input field for the editor. Will be a textarea or an editable div, depending on the value of the inputStyle option.
-
getKeyMap(
) → String? - Return the current key map.
-
getLine(
int? n) → String? - Get the content of line n.
-
getLineNumbers(
) → bool? - Whether to show line numbers to the left of the editor.
-
getLineTokens(
int line, [bool? precise]) → List< Token> - This is similar to getTokenAt, but collects all tokens for a given line into an array. It is much cheaper than repeatedly calling getTokenAt, which re-parses the part of the line before the token for every call.
-
getMode(
) → String? -
getOption(
String option) → dynamic - Retrieves the current value of the given option for this editor instance.
-
getReadOnly(
) → bool - Whether editing is disabled.
-
getScrollInfo(
) → ScrollInfo - Get a ScrollInfo object that represents the current scroll position, the size of the scrollable area, and the size of the visible area (minus scrollbars).
-
getTabSize(
) → int - The width of a tab character. Defaults to 4.
-
getTextArea(
) → TextAreaElement? - Returns the textarea that the instance was based on.
-
getTheme(
) → String? -
getTokenAt(
Position pos, [bool? precise]) → Token - Retrieves information about the token the current mode found before the given position.
-
getTokenTypeAt(
Position pos) → String? - This is a (much) cheaper version of getTokenAt useful for when you just need the type of the token at a given position, and no other information. Will return null for unstyled tokens, and a string, potentially containing multiple space-separated style names, otherwise.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onEvent<
T> (String eventName, {int argCount = 1}) → Stream< T?> -
inherited
-
refresh(
) → void - If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it, you should probably follow up by calling this method to ensure CodeMirror is still looking as intended.
-
removeLineClass(
dynamic line, String where, [String? cssClass]) → LineHandle -
Remove a CSS class from a line.
line
can be a LineHandle or number.where
should be one of "text", "background", or "wrap" (see addLineClass).cssClass
can be left off to remove all classes for the specified node, or be a string to remove only a specific class. -
save(
) → void - Copy the content of the editor into the textarea.
-
scrollIntoView(
int line, int ch, {int? margin}) → void - Scrolls the given position into view. The margin parameter is optional. When given, it indicates the amount of vertical pixels around the given area that should be made visible as well.
-
scrollTo(
num? x, num? y) → void - Scroll the editor to a given (pixel) position. Both arguments may be left as null or undefined to have no effect.
-
setGutterMarker(
int line, String gutterID, Element value) → void - Sets the gutter marker for the given gutter (identified by its CSS class, see the gutters option) to the given value. Value can be either null, to clear the marker, or a DOM element, to set it. The DOM element will be shown in the specified gutter next to the specified line.
-
setIndentUnit(
int value) → void - How many spaces a block (whatever that means in the edited language) should be indented.
-
setIndentWithTabs(
bool? value) → void - Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs.
-
setKeyMap(
String value) → void -
Valid options are
default
,vim
,emacs
, andsublime
. -
setLineNumbers(
bool? value) → void - Whether to show line numbers to the left of the editor.
-
setMode(
String mode) → void -
setOption(
String option, dynamic value) → void -
Change the configuration of the editor.
option
should the name of an option, and value should be a valid value for that option. -
setReadOnly(
bool value, [bool noCursor = false]) → void - This disables editing of the editor content by the user.
-
setSize(
num? width, num? height) → void -
Programmatically set the size of the editor (overriding the applicable CSS
rules).
width
andheight
are numbers (interpreted as pixels). You can passnull
for either of them to indicate that that dimension should not be changed. -
setSizeInCssUnits(
String? width, String? height) → void -
Programmatically set the size of the editor (overriding the applicable CSS
rules).
width
andheight
should be CSS units ("100%", for example). You can passnull
for either of them to indicate that that dimension should not be changed. -
setTabSize(
int value) → void - The width of a tab character.
-
setTheme(
String theme) → void -
swapDoc(
Doc doc) → void - Attach a new document to the editor.
-
toString(
) → String -
A string representation of this object.
inherited
-
toTextArea(
) → void - Remove the editor, and restore the original textarea (with the editor's current content).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
commands
→ List<
String> -
no setter
-
COMMANDS
→ List<
String> -
no setter
-
MIME_MODES
→ List<
String> -
no setter
-
mimeModes
→ List<
String> -
no setter
-
modes
→ List<
String> -
no setter
-
MODES
→ List<
String> -
no setter
- version → String?
-
It contains a string that indicates the version of the library. This is a
triple of integers "major.minor.patch", where patch is zero for releases,
and something else (usually one) for dev snapshots.
no setter
Static Methods
-
addCommand(
String name, CommandHandler callback) → void - Add a new custom command to CodeMirror.
-
defineDocExtension(
String name, dynamic value) → void - Like defineExtension, but the method will be added to the interface for Doc objects instead.
-
defineExtension(
String name, dynamic value) → void - If you want to define extra methods in terms of the CodeMirror API, it is possible to use defineExtension. This will cause the given value (usually a method) to be added to all CodeMirror instances created from then on.
-
findModeByExtension(
String ext) → ModeInfo -
findModeByFileName(
String name) → ModeInfo -
findModeByMime(
String mime) → ModeInfo -
findModeByName(
String name) → ModeInfo -
registerHelper(
String type, String mode, dynamic helper) → void - Registers a helper value with the given name in the given namespace (type). This is used to define functionality that may be looked up by mode. Will create (if it doesn't already exist) a property on the CodeMirror object for the given type, pointing to an object that maps names to values. I.e. after doing CodeMirror.registerHelper("hint", "foo", myFoo), the value CodeMirror.hint.foo will point to myFoo.