CodeLineEditingController class abstract

A controller for an editor field.

Whenever the user modifies a editor field with an associated CodeLineEditingController, the editor field updates value and the controller notifies its listeners. Listeners can then read the codeLines and selection properties to learn what the user has typed or how the selection has been updated.

Similarly, if you modify the codeLines or selection properties, the editor field will be notified and will update itself appropriately.

A CodeLineEditingController can also be used to provide an initial value for a editor field. If you build a editor field with a controller that already has codeLines, the editor field will use that text as its initial value.

The value (as well as codeLines and selection) of this controller can be updated from within a listener added to this controller. Be aware of infinite loops since the listener will also be notified of the changes made from within itself. Modifying the composing region from within a listener can also have a bad interaction with some input methods. Gboard, for example, will try to restore the composing region of the text if it was modified programmatically, creating an infinite loop of communications between the framework and the input method.

If both the codeLines or selection properties need to be changed, set the controller's value instead.

Remember to dispose of the CodeLineEditingController when it is no longer needed. This will ensure we discard any resources used by the object.

Inheritance
Implementers

Constructors

CodeLineEditingController({CodeLines codeLines = _kInitialCodeLines, CodeLineOptions options = const CodeLineOptions(), CodeLineSpanBuilder? spanBuilder})
Creates a controller for an editor field.
factory
CodeLineEditingController.fromText(String? text, [CodeLineOptions options = const CodeLineOptions()])
Creates a controller for a given text.
factory
CodeLineEditingController.fromTextAsync(String? text, [CodeLineOptions options = const CodeLineOptions()])
Creates a controller for a given file path. The file content will read async.
factory

Properties

baseLine CodeLine
The code line at which the selection originates.
no setter
canRedo bool
Whether the redo action can be performed.
no setter
canUndo bool
Whether the undo action can be performed.
no setter
codeLines CodeLines
The current codes the user is editing.
getter/setter pair
composing TextRange
Get the range of code that is still being composed.
getter/setter pair
endLine CodeLine
The code line at which the selection ends.
no setter
extentLine CodeLine
The code line at which the selection terminates.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isAllSelected bool
Whether all the codes are selected.
no setter
isComposing bool
Whether the code that is still being composed.
no setter
isEmpty bool
Whether the code is empty.
no setter
lineCount int
How many lines in the editor.
no setter
options CodeLineOptions
Get the code line options.
no setter
preValue CodeLineEditingValue?
Get the previous editing value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedText String
The current text being selected.
no setter
selection CodeLineSelection
Get the current editor code selections.
getter/setter pair
startLine CodeLine
The code line at which the selection starts.
no setter
text String
The current text being edited.
getter/setter pair
textAsync String
Set the current editor text async.
no getter
unforldLineSelection CodeLineSelection
Expanded code selections.
no setter
value CodeLineEditingValue
The current value stored in this notifier.
getter/setter pairinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
applyIndent() → void
Insert a indent.
applyNewLine() → void
Insert a newline character.
applyOutdent() → void
Delete a indent.
bindEditor(GlobalKey<State<StatefulWidget>> key) → void
Only used in internal.
buildTextSpan({required BuildContext context, required int index, required TextSpan textSpan, required TextStyle style}) TextSpan
Builds TextSpan from current editing value. This can override the code syntax highlighting styles.
cancelSelection() → void
The selection will be collaposed at the terminate position.
clearComposing() → void
Set the composing region to an empty range.
collapseChunk(int start, int end) → void
Collapse codes form start to end.
copy() Future<void>
If the selection is currently collapsed, the whole line will be copied. Otherwise, copy the selected codes.
cut() → void
If the selection is currently collapsed, the whole line will be cut. Otherwise, cut the selected codes.
deleteBackward() → void
If the selection is currently collapsed, the character behind the cursor will be deleted. Otherwise, will delete the selection, same as deleteSelection.
deleteForward() → void
If the selection is currently collapsed, the character in front of the cursor will be deleted. Otherwise, will delete the selection, same as deleteSelection.
deleteSelection() → void
Delete the selected codes.
deleteSelectionLines([bool keepExtentOffset = true]) → void
Delete the selected lines.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
edit(TextEditingValue newValue) → void
Set the current editor value.
expandChunk(int index) → void
Expand the codes at index of lines.
extendSelection(AxisDirection direction) → void
Extend the selection to a direction.
extendSelectionToLineEnd() → void
Extend the selection to the end of current line.
extendSelectionToLineStart() → void
Extend the selection to the start of current line.
extendSelectionToPageEnd() → void
Extend the selection to the end of document.
extendSelectionToPageStart() → void
Extend the selection to the start of document.
extendSelectionToWordBoundaryBackward() → void
Extend the selection to the end of the word.
extendSelectionToWordBoundaryForward() → void
Extend the selection to the start of the word.
forceRepaint() → void
Force the render to repaint.
index2lineIndex(int index) int
Convert the index to the unforld line index.
lineIndex2Index(int lineIndex) CodeLineIndex
Get code line information at lineIndex.
makeCursorCenterIfInvisible() → void
Scroll the editor to make sure the cursor is visible at center.
makeCursorVisible() → void
Scroll the editor to make sure the cursor is visible.
makePositionCenterIfInvisible(CodeLinePosition position) → void
Scroll the editor to make sure the given position is visible at center.
makePositionVisible(CodeLinePosition position) → void
Scroll the editor to make sure the given position is visible.
moveCursor(AxisDirection direction) → void
Move the cursor to a direction.
moveCursorToLineEnd() → void
Move the cursor to the end of current line.
moveCursorToLineStart() → void
Move the cursor to the start of current line.
moveCursorToPageDown() → void
TODO
moveCursorToPageEnd() → void
Move the cursor to the end of document.
moveCursorToPageStart() → void
Move the cursor to the start of document.
moveCursorToPageUp() → void
TODO
moveCursorToWordBoundaryBackward() → void
Move the cursor to the end of the word.
moveCursorToWordBoundaryForward() → void
Move the cursor to the start of the word.
moveSelectionLinesDown() → void
Move down the selected code lines.
moveSelectionLinesUp() → void
Move up the selected code lines.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
paste() → void
Paste text from Clipboard.
redo() → void
Updates the value on the stack to the next value.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
replaceAll(Pattern pattern, String replacement) → void
Replaces all substrings that match pattern with replacement.
replaceSelection(String replacement, [CodeLineSelection? selection]) → void
Replace the selected code with a new string replacement.
runRevocableOp(VoidCallback op) → void
Perform an operation. If the editor content changes, it will be recorded in the undo history.
selectAll() → void
Select all the codes.
selectLine(int index) → void
Select a code line at the given index.
selectLines(int base, int extent) → void
Select some code lines at the given start and end index.
toString() String
A string representation of this object.
inherited
transposeCharacters() → void
Transpose characters.
undo() → void
Reverts the value on the stack to the previous value.

Operators

operator ==(Object other) bool
The equality operator.
inherited