Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support disabling keyboard & scroll service #852

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions lib/src/editor/editor_component/service/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class AppFlowyEditor extends StatefulWidget {
this.enableAutoComplete = false,
this.autoCompleteTextProvider,
this.dropTargetStyle,
this.disableSelection = false,
this.disableSelectionService = false,
this.disableKeyboardService = false,
this.disableScrollService = false,
}) : blockComponentBuilders =
blockComponentBuilders ?? standardBlockComponentBuilderMap,
characterShortcutEvents =
Expand Down Expand Up @@ -195,7 +197,19 @@ class AppFlowyEditor extends StatefulWidget {
final AppFlowyDropTargetStyle? dropTargetStyle;

/// Disable the selection gesture
final bool disableSelection;
///
/// It will disable the selection service and the context menu.
final bool disableSelectionService;

/// Disable the keyboard service
///
/// It will disable all the keyboard shortcuts and the text input.
final bool disableKeyboardService;

/// Disable the scroll service
///
/// It will disable the auto scroll feature.
final bool disableScrollService;

@override
State<AppFlowyEditor> createState() => _AppFlowyEditorState();
Expand Down Expand Up @@ -285,19 +299,21 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {
footer: widget.footer,
);

child = KeyboardServiceWidget(
key: editorState.service.keyboardServiceKey,
// disable all the shortcuts when the editor is not editable
characterShortcutEvents:
widget.editable ? widget.characterShortcutEvents : [],
// only allow copy and select all when the editor is not editable
commandShortcutEvents: widget.commandShortcutEvents,
focusNode: widget.focusNode,
contentInsertionConfiguration: widget.contentInsertionConfiguration,
child: child,
);
if (!widget.disableKeyboardService) {
child = KeyboardServiceWidget(
key: editorState.service.keyboardServiceKey,
// disable all the shortcuts when the editor is not editable
characterShortcutEvents:
widget.editable ? widget.characterShortcutEvents : [],
// only allow copy and select all when the editor is not editable
commandShortcutEvents: widget.commandShortcutEvents,
focusNode: widget.focusNode,
contentInsertionConfiguration: widget.contentInsertionConfiguration,
child: child,
);
}

if (widget.disableSelection) {
if (!widget.disableSelectionService) {
child = SelectionServiceWidget(
key: editorState.service.selectionServiceKey,
cursorColor: widget.editorStyle.cursorColor,
Expand All @@ -309,11 +325,15 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {
);
}

return ScrollServiceWidget(
key: editorState.service.scrollServiceKey,
editorScrollController: editorScrollController,
child: child,
);
if (!widget.disableScrollService) {
child = ScrollServiceWidget(
key: editorState.service.scrollServiceKey,
editorScrollController: editorScrollController,
child: child,
);
}

return child;
}

void _autoFocusIfNeeded() {
Expand Down
Loading