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 keyboard gesture on mobile #905

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
RawFloatingCursorPoint point,
EditorState editorState,
) async {
AppFlowyEditorLog.input
.debug('onFloatingCursorUpdate: ${point.state}, ${point.offset}');
AppFlowyEditorLog.input.debug(
'onFloatingCursorUpdate: ${point.state}, ${point.offset}',

Check warning on line 15 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L14-L15

Added lines #L14 - L15 were not covered by tests
);

// support updating the cursor position via the space bar on iOS/Android.
if (PlatformExtension.isDesktopOrWeb) {
Expand All @@ -26,9 +27,16 @@
final collapsedCursor = HandleType.collapsed.key;
final context = collapsedCursor.currentContext;
if (context == null) {
AppFlowyEditorLog.input.debug(

Check warning on line 30 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L30

Added line #L30 was not covered by tests
'onFloatingCursorUpdateStart: context is null',
);
return;
}

AppFlowyEditorLog.input.debug(
'onFloatingCursorUpdateStart: ${point.startLocation}',

Check warning on line 37 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L36-L37

Added lines #L36 - L37 were not covered by tests
);

// get global offset of the cursor.
final renderBox = context.findRenderObject() as RenderBox;
final offset = renderBox.localToGlobal(Offset.zero);
Expand All @@ -44,10 +52,26 @@
);
break;
case FloatingCursorDragState.Update:
final collapsedCursor = HandleType.collapsed.key;
final context = collapsedCursor.currentContext;

Check warning on line 56 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L55-L56

Added lines #L55 - L56 were not covered by tests
if (context == null) {
AppFlowyEditorLog.input.debug(

Check warning on line 58 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L58

Added line #L58 was not covered by tests
'onFloatingCursorUpdateUpdate: context is null',
);
return;
} else {
AppFlowyEditorLog.input.debug(

Check warning on line 63 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L63

Added line #L63 was not covered by tests
'onFloatingCursorUpdateUpdate: context is not null',
);
}
if (_cursorOffset == null || point.offset == null) {
return;
}

AppFlowyEditorLog.input.debug(
'onFloatingCursorUpdateUpdate: ${point.offset}',

Check warning on line 72 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L71-L72

Added lines #L71 - L72 were not covered by tests
);

disableMagnifier = true;
selectionService.onPanUpdate(
DragUpdateDetails(
Expand All @@ -57,6 +81,10 @@
);
break;
case FloatingCursorDragState.End:
AppFlowyEditorLog.input.debug(
'onFloatingCursorUpdateEnd: ${point.offset}',

Check warning on line 85 in lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart#L84-L85

Added lines #L84 - L85 were not covered by tests
);

_cursorOffset = null;
disableMagnifier = false;
selectionService.onPanEnd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@
),
);
}
} else if (PlatformExtension.isAndroid) {

Check warning on line 56 in lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart#L56

Added line #L56 was not covered by tests
// on some Android keyboards (e.g. Gboard), they use non-text update to update the selection when moving cursor
// by space bar.
// for the another keyboards (e.g. system keyboard), they will trigger the
// `onFloatingCursor` event instead.
AppFlowyEditorLog.input.debug('[Android] onNonTextUpdate: $nonTextUpdate');

Check warning on line 61 in lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart#L61

Added line #L61 was not covered by tests
if (selection != null) {
editorState.updateSelectionWithReason(
Selection.collapsed(
Position(
path: selection.start.path,
offset: nonTextUpdate.selection.start,

Check warning on line 67 in lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart#L63-L67

Added lines #L63 - L67 were not covered by tests
),
),
);
}
} else if (PlatformExtension.isIOS) {

Check warning on line 72 in lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart#L72

Added line #L72 was not covered by tests
// on iOS, the cursor movement will trigger the `onFloatingCursor` event.
// so we don't need to handle the non-text update here.
AppFlowyEditorLog.input.debug('[iOS] onNonTextUpdate: $nonTextUpdate');

Check warning on line 75 in lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart#L75

Added line #L75 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
// on iOS, when using gesture to move cursor, this function will be called
// which may cause the unneeded delta being applied
// so we ignore the updateEditingValue event when the floating cursor is visible
AppFlowyEditorLog.editor.debug(

Check warning on line 109 in lib/src/editor/editor_component/service/ime/non_delta_input_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/ime/non_delta_input_service.dart#L109

Added line #L109 was not covered by tests
'ignore updateEditingValue event when the floating cursor is visible',
);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@
return ValueListenableBuilder(
valueListenable: selectionNotifierAfterLayout,
builder: (context, selection, _) {
if (selection == null ||
!selection.isCollapsed ||
if (selection == null || !selection.isCollapsed) {

Check warning on line 180 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L180

Added line #L180 was not covered by tests
return const SizedBox.shrink();
}

// on iOS, the drag handle should be updated when typing text.
if (PlatformExtension.isAndroid &&

Check warning on line 185 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L185

Added line #L185 was not covered by tests
editorState.selectionUpdateReason !=
SelectionUpdateReason.uiEvent) {
return const SizedBox.shrink();
Expand Down
Loading