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

[SuperEditor] Create IME visualizer (Resolves #1120) #1311

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
66 changes: 54 additions & 12 deletions super_editor/example/lib/demos/example_editor/example_editor.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:example/demos/example_editor/text_input_visualizer.dart';
import 'package:example/logging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -43,6 +44,9 @@ class _ExampleEditorState extends State<ExampleEditor> {
final _overlayController = MagnifierAndToolbarController() //
..screenPadding = const EdgeInsets.all(20.0);

final TextInputDebugger _textInputDebugger = TextInputDebugger();
bool _showImeDebugger = false;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -319,20 +323,33 @@ class _ExampleEditorState extends State<ExampleEditor> {
child: Builder(
builder: (themedContext) {
// This builder captures the new theme
return Stack(
return Row(
children: [
Column(
children: [
Expanded(
child: _buildEditor(themedContext),
),
if (_isMobile) _buildMountedToolbar(),
],
),
Align(
alignment: Alignment.bottomRight,
child: _buildCornerFabs(),
Expanded(
child: Stack(
children: [
Column(
children: [
Expanded(
child: _buildEditor(themedContext),
),
if (_isMobile) _buildMountedToolbar(),
],
),
Align(
alignment: Alignment.bottomRight,
child: _buildCornerFabs(),
),
],
),
),
if (_showImeDebugger)
SizedBox(
width: 400,
child: SuperEditorImeDebugger(
debugger: _textInputDebugger,
),
),
],
);
},
Expand All @@ -349,6 +366,8 @@ class _ExampleEditorState extends State<ExampleEditor> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildImeDebuggerToggle(),
const SizedBox(height: 16),
_buildDebugVisualsToggle(),
const SizedBox(height: 16),
_buildLightAndDarkModeToggle(),
Expand All @@ -357,6 +376,28 @@ class _ExampleEditorState extends State<ExampleEditor> {
);
}

Widget _buildImeDebuggerToggle() {
return FloatingActionButton(
backgroundColor: _brightness.value == Brightness.light ? _darkBackground : _lightBackground,
foregroundColor: _brightness.value == Brightness.light ? _lightBackground : _darkBackground,
elevation: 5,
onPressed: () {
setState(() {
_showImeDebugger = !_showImeDebugger;

if (_showImeDebugger) {
_textInputDebugger.enable();
} else {
_textInputDebugger.disable();
}
});
},
child: const Icon(
Icons.translate,
),
);
}

Widget _buildDebugVisualsToggle() {
return FloatingActionButton(
backgroundColor: _brightness.value == Brightness.light ? _darkBackground : _lightBackground,
Expand Down Expand Up @@ -410,6 +451,7 @@ class _ExampleEditorState extends State<ExampleEditor> {
focusNode: _editorFocusNode,
scrollController: _scrollController,
documentLayoutKey: _docLayoutKey,
textInputDebugger: _textInputDebugger,
documentOverlayBuilders: [
DefaultCaretOverlayBuilder(
caretStyle: const CaretStyle().copyWith(color: isLight ? Colors.black : Colors.redAccent),
Expand Down
Loading