CodeForgeController class

Controller for the CodeForge code editor widget.

This controller manages the text content, selection state, and various editing operations for the code editor. It implements DeltaTextInputClient to handle text input from the platform.

The controller uses a rope data structure internally for efficient text manipulation, especially for large documents.

Example:

final controller = CodeForgeController();
controller.text = 'void main() {\n  print("Hello");\n}';

// Access selection
print(controller.selection);

// Get specific line
print(controller.getLineText(0)); // 'void main() {'

// Fold/unfold code
controller.foldAll();
controller.unfoldAll();
Implemented types

Constructors

CodeForgeController()

Properties

bufferCursorColumn int
no setter
bufferLineIndex int?
no setter
bufferLineRopeStart int
no setter
bufferLineText String?
no setter
bufferNeedsRepaint bool
getter/setter pair
connection TextInputConnection?
The text input connection to the platform.
getter/setter pair
currentAutofillScope AutofillScope?
The AutofillScope this TextInputClient belongs to, if any.
no setteroverride
currentTextEditingValue TextEditingValue?
The current state of the TextEditingValue held by this client.
no setteroverride
dirtyLine int?
getter/setter pair
dirtyRegion TextRange?
The range of text that has been modified and needs reprocessing.
getter/setter pair
foldings List<FoldRange>
List of all fold ranges detected in the document.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isBufferActive bool
no setter
length int
The total length of the document in characters.
no setter
lineCount int
The total number of lines in the document.
no setter
lines List<String>
List of all lines in the document.
no setter
lineStructureChanged bool
Whether the line structure has changed (lines added or removed).
getter/setter pair
manualAiCompletion VoidCallback?
Callback for manually triggering AI completion. Set this to enable custom AI completion triggers.
getter/setter pair
openedFile String?
Currently opened file.
getter/setter pair
readOnly bool
Whether the editor is in read-only mode.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchHighlights List<SearchHighlight>
List of search highlights to display in the editor.
getter/setter pair
searchHighlightsChanged bool
Whether the search highlights have changed and need repaint.
getter/setter pair
selection TextSelection
The current text selection in the editor.
getter/setter pair
selectionOnly bool
getter/setter pair
text String
The complete text content of the editor.
getter/setter pair
visibleText String
The visible text content with folded regions hidden.
no setter

Methods

addListener(VoidCallback listener) → void
Adds a listener that will be called when the controller state changes.
backspace() → void
Remove the selection or last char if the selection is empty (backspace key)
clearDirtyRegion() → void
clearSearchHighlights() → void
Clear all search highlights
connectionClosed() → void
Platform notified framework of closed connection.
override
copy() → void
Copies the currently selected text to the clipboard.
cut() → void
Cuts the currently selected text to the clipboard.
delete() → void
Remove the selection or the char at cursor position (delete key)
didChangeInputControl(TextInputControl? oldControl, TextInputControl? newControl) → void
The framework calls this method to notify that the text input control has been changed.
override
dispose() → void
Disposes of the controller and releases resources.
findLineEnd(int offset) int
Finds the end of the line containing offset.
findLineStart(int offset) int
Finds the start of the line containing offset.
findRegex(RegExp regex, TextStyle? highlightStyle) → void
findWord(String word, {TextStyle? highlightStyle, bool matchCase = false, bool matchWholeWord = false}) → void
foldAll() → void
Folds all foldable regions in the document.
getLineAtOffset(int charOffset) int
Gets the line number (zero-based) for a character offset.
getLineStartOffset(int lineIndex) int
Gets the character offset where a line starts.
getLineText(int lineIndex) String
Gets the text content of a specific line.
getManualAiSuggestion() → void
Callback to show Ai suggestion manually when the AiCompletion.completionType is CompletionType.manual or CompletionType.mixed.
insertAtCurrentCursor(String textToInsert, {bool replaceTypedChar = false}) → void
Insert text at the current cursor position (or replace selection).
insertContent(KeyboardInsertedContent content) → void
Notify client about new content insertion from Android keyboard.
override
insertTextPlaceholder(Size size) → void
Requests that the client add a text placeholder to reserve visual space in the text.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Notifies all registered listeners of a state change.
paste() Future<void>
Pastes text from the clipboard at the current cursor position.
performAction(TextInputAction action) → void
Requests that this client perform the given action.
override
performPrivateCommand(String action, Map<String, dynamic> data) → void
Request from the input method that this client perform the given private command.
override
performSelector(String selectorName) → void
Performs the specified MacOS-specific selector from the NSStandardKeyBindingResponding protocol or user-specified selector from DefaultKeyBinding.Dict.
override
pressDownArrowKey({bool isShiftPressed = false}) → void
Moves the cursor down one line, maintaining the column position.
pressEndKey({bool isShiftPressed = false}) → void
Moves the cursor to the end of the current line.
pressHomeKey({bool isShiftPressed = false}) → void
Moves the cursor to the beginning of the current line.
pressLetfArrowKey({bool isShiftPressed = false}) → void
Moves the cursor one character to the left.
pressRightArrowKey({bool isShiftPressed = false}) → void
Moves the cursor one character to the right.
pressUpArrowKey({bool isShiftPressed = false}) → void
Moves the cursor up one line, maintaining the column position.
removeListener(VoidCallback listener) → void
Removes a previously added listener.
removeTextPlaceholder() → void
Requests that the client remove the text placeholder.
override
replaceRange(int start, int end, String replacement) → void
Replace a range of text with new text. Used for clipboard operations and text manipulation.
saveFile() → void
Save the current content, controller.text to the opened file.
selectAll() → void
Selects all text in the editor.
setFoldCallbacks({void toggleFold(int lineNumber)?, VoidCallback? foldAll, VoidCallback? unfoldAll}) → void
Set fold operation callbacks - called by the render object
setSelectionSilently(TextSelection newSelection) → void
Updates selection and syncs to text input connection for keyboard navigation.
setUndoController(UndoRedoController? controller) → void
Sets the undo controller for this editor.
showAutocorrectionPromptRect(int start, int end) → void
Requests that this client display a prompt rectangle for the given text range, to indicate the range of text that will be changed by a pending autocorrection.
override
showToolbar() → void
Requests that the client show the editing toolbar, for example when the platform changes the selection through a non-flutter method such as scribble.
override
toggleFold(int lineNumber) → void
Toggles the fold state at the specified line number.
toString() String
A string representation of this object.
inherited
unfoldAll() → void
Unfolds all folded regions in the document.
updateEditingValue(TextEditingValue value) → void
Requests that this client update its editing state to the given value.
override
updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) → void
Requests that this client update its editing state by applying the deltas received from the engine.
override
updateFloatingCursor(RawFloatingCursorPoint point) → void
Updates the floating cursor position and state.
override

Operators

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