Skip to content

Commit

Permalink
feat(editor): support move cursor to end of document on startup
Browse files Browse the repository at this point in the history
This commit added a flag to move cursor to the end of document once the
document is setup during editor startup.

Enabled by default.
  • Loading branch information
realth000 committed Nov 17, 2024
1 parent 724e286 commit 2e3ac4a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/src/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BBCodeEditor extends StatefulWidget {
this.initialText,
this.imageConstraints,
this.usernamePicker,
this.moveCursorToEndOnInitState = true,
super.key,
}) : _controller = controller;

Expand Down Expand Up @@ -76,6 +77,10 @@ class BBCodeEditor extends StatefulWidget {
/// Optional initial text.
final String? initialText;

/// Enable this flag if intend to move the cursor to the end of document once
/// the [initialText] applied to the editor.
final bool moveCursorToEndOnInitState;

/// Optional layout constraints when rendering image.
final BoxConstraints? imageConstraints;

Expand All @@ -93,6 +98,9 @@ class _BBCodeEditorState extends State<BBCodeEditor> {
if (widget.initialText != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_controllerV2.setDocumentFromRawText(widget.initialText!);
if (widget.moveCursorToEndOnInitState) {
_controllerV2.moveCursorToEnd();
}
});
}
}
Expand Down

0 comments on commit 2e3ac4a

Please sign in to comment.