Skip to content

Commit

Permalink
[SuperTextField][Desktop] Implement IME input source (Resolves #892) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed Dec 22, 2022
1 parent 2bff31e commit 7192947
Show file tree
Hide file tree
Showing 27 changed files with 354 additions and 141 deletions.
2 changes: 1 addition & 1 deletion super_editor/example/lib/demos/demo_empty_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _EmptyDocumentDemoState extends State<EmptyDocumentDemo> {
child: SuperEditor(
editor: _docEditor,
gestureMode: DocumentGestureMode.mouse,
inputSource: DocumentInputSource.keyboard,
inputSource: TextInputSource.keyboard,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _MobileEditingAndroidDemoState extends State<MobileEditingAndroidDemo> {
composer: _composer,
softwareKeyboardHandler: _softwareKeyboardHandler,
gestureMode: DocumentGestureMode.android,
inputSource: DocumentInputSource.ime,
inputSource: TextInputSource.ime,
androidToolbarBuilder: (_) => AndroidTextEditingFloatingToolbar(
onCutPressed: () => _docOps.cut(),
onCopyPressed: () => _docOps.copy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _MobileEditingIOSDemoState extends State<MobileEditingIOSDemo> {
editor: _docEditor,
composer: _composer,
gestureMode: DocumentGestureMode.iOS,
inputSource: DocumentInputSource.ime,
inputSource: TextInputSource.ime,
iOSToolbarBuilder: (_) => IOSTextEditingFloatingToolbar(
onCutPressed: () => _docOps.cut(),
onCopyPressed: () => _docOps.copy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ class _ExampleEditorState extends State<ExampleEditor> {

bool get _isMobile => _gestureMode != DocumentGestureMode.mouse;

DocumentInputSource get _inputSource {
TextInputSource get _inputSource {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.iOS:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
return DocumentInputSource.ime;
return TextInputSource.ime;
// return DocumentInputSource.keyboard;
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ class _ExampleEditorState extends State<ExampleEditor> {
],
gestureMode: _gestureMode,
inputSource: _inputSource,
keyboardActions: _inputSource == DocumentInputSource.ime ? defaultImeKeyboardActions : defaultKeyboardActions,
keyboardActions: _inputSource == TextInputSource.ime ? defaultImeKeyboardActions : defaultKeyboardActions,
androidToolbarBuilder: (_) => AndroidTextEditingFloatingToolbar(
onCutPressed: _cut,
onCopyPressed: _copy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class _InteractiveTextFieldDemoState extends State<InteractiveTextFieldDemo> {
width: double.infinity,
child: SuperDesktopTextField(
textController: _textFieldController,
inputSource: TextInputSource.ime,
focusNode: _focusNode,
textStyleBuilder: _textStyleBuilder,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
Expand Down
6 changes: 0 additions & 6 deletions super_editor/lib/src/core/document_interaction.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/// The mode of user text input.
enum DocumentInputSource {
keyboard,
ime,
}

/// The mode of user gesture input.
enum DocumentGestureMode {
mouse,
Expand Down
25 changes: 13 additions & 12 deletions super_editor/lib/src/default_editor/super_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:super_editor/src/default_editor/document_gestures_touch_ios.dart
import 'package:super_editor/src/default_editor/document_scrollable.dart';
import 'package:super_editor/src/default_editor/list_items.dart';
import 'package:super_editor/src/infrastructure/platforms/ios/ios_document_controls.dart';
import 'package:super_editor/src/infrastructure/text_input.dart';
import 'package:super_text_layout/super_text_layout.dart';

import '../infrastructure/platforms/mobile_documents.dart';
Expand Down Expand Up @@ -84,7 +85,7 @@ class SuperEditor extends StatefulWidget {
this.documentLayoutKey,
Stylesheet? stylesheet,
this.customStylePhases = const [],
this.inputSource = DocumentInputSource.keyboard,
this.inputSource = TextInputSource.keyboard,
this.gestureMode = DocumentGestureMode.mouse,
this.androidHandleColor,
this.androidToolbarBuilder,
Expand Down Expand Up @@ -114,7 +115,7 @@ class SuperEditor extends StatefulWidget {
this.customStylePhases = const [],
List<ComponentBuilder>? componentBuilders,
SelectionStyles? selectionStyle,
this.inputSource = DocumentInputSource.keyboard,
this.inputSource = TextInputSource.keyboard,
this.gestureMode = DocumentGestureMode.mouse,
List<DocumentKeyboardAction>? keyboardActions,
this.softwareKeyboardHandler,
Expand Down Expand Up @@ -217,7 +218,7 @@ class SuperEditor extends StatefulWidget {
final List<SingleColumnLayoutStylePhase> customStylePhases;

/// The `SuperEditor` input source, e.g., keyboard or Input Method Engine.
final DocumentInputSource? inputSource;
final TextInputSource? inputSource;

/// The `SuperEditor` gesture mode, e.g., mouse or touch.
final DocumentGestureMode? gestureMode;
Expand Down Expand Up @@ -263,13 +264,13 @@ class SuperEditor extends StatefulWidget {
/// events, e.g., text entry, newlines, character deletion,
/// copy, paste, etc.
///
/// These actions are only used when in [DocumentInputSource.keyboard]
/// These actions are only used when in [TextInputSource.keyboard]
/// mode.
final List<DocumentKeyboardAction> keyboardActions;

/// Applies all software keyboard edits to the document.
///
/// This handler is only used when in [DocumentInputSource.ime] mode.
/// This handler is only used when in [TextInputSource.ime] mode.
final SoftwareKeyboardHandler? softwareKeyboardHandler;

/// Paints some extra visual ornamentation to help with
Expand Down Expand Up @@ -503,20 +504,20 @@ class SuperEditorState extends State<SuperEditor> {
}
}

/// Returns the [DocumentInputSource] which should be used.
/// Returns the [TextInputSource] which should be used.
///
/// If the `inputSource` is configured, it is used. Otherwise,
/// the [DocumentInputSource] is chosen based on the platform.
DocumentInputSource get _inputSource {
/// the [TextInputSource] is chosen based on the platform.
TextInputSource get _inputSource {
if (widget.inputSource != null) {
return widget.inputSource!;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.iOS:
return DocumentInputSource.ime;
return TextInputSource.ime;
default:
return DocumentInputSource.keyboard;
return TextInputSource.keyboard;
}
}

Expand All @@ -540,15 +541,15 @@ class SuperEditorState extends State<SuperEditor> {
required Widget child,
}) {
switch (_inputSource) {
case DocumentInputSource.keyboard:
case TextInputSource.keyboard:
return DocumentKeyboardInteractor(
focusNode: _focusNode,
autofocus: widget.autofocus,
editContext: editContext,
keyboardActions: widget.keyboardActions,
child: child,
);
case DocumentInputSource.ime:
case TextInputSource.ime:
return DocumentImeInteractor(
focusNode: _focusNode,
autofocus: widget.autofocus,
Expand Down
Loading

0 comments on commit 7192947

Please sign in to comment.