Skip to content

Commit

Permalink
fix: flutter anlayze
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Feb 28, 2024
1 parent 9b9b2e7 commit 2492b25
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 230 deletions.
2 changes: 1 addition & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class _HomePageState extends State<HomePage> {
html.toJson(),
).toString(),
);
if (mounted) {
if (context.mounted) {
_loadEditor(context, jsonString);
}
}),
Expand Down
2 changes: 0 additions & 2 deletions lib/src/core/transform/operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class UpdateTextOperation extends Operation {
int get hashCode => delta.hashCode ^ inverted.hashCode;
}

// TODO(Lucas.Xu): refactor this part
Path transformPath(Path preInsertPath, Path b, [int delta = 1]) {
if (preInsertPath.length > b.length || preInsertPath.isEmpty || b.isEmpty) {
return b;
Expand Down Expand Up @@ -269,6 +268,5 @@ Operation? transformOperation(Operation a, Operation b) {
return b.copyWith(path: newPath);
}

// TODO: transform update and textedit
return b;
}
1 change: 0 additions & 1 deletion lib/src/core/transform/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ extension TextTransaction on Transaction {
);
}

// TODO: refactor this code
void replaceTexts(
List<Node> nodes,
Selection selection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class _TodoListBlockComponentWidgetState
});

if (widget.toggleChildrenTriggers != null &&
RawKeyboard.instance.keysPressed.any(
HardwareKeyboard.instance.logicalKeysPressed.any(
(element) => widget.toggleChildrenTriggers!.contains(element),
)) {
checkOrUncheckChildren(!checked, widget.node);
Expand Down
1 change: 0 additions & 1 deletion lib/src/editor/command/selection_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ extension SelectionTransform on EditorState {

/// move the cursor forward.
///
/// TODO: I think we should add move forward function to the SelectableMixin.
/// Don't hardcode the logic here.
/// For example,
/// final position = node.selectable?.moveForward(selection.startIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
apply(textEditingDeltas);
}

// TODO: support IME in linux / windows / ios / android
// Only support macOS now.
@override
void updateCaretPosition(Size size, Matrix4 transform, Rect rect) {
_textInputConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
_textInputConnection = null;
}

// TODO: support IME in linux / ios / android
// Only verify in macOS and Windows now.
@override
void updateCaretPosition(Size size, Matrix4 transform, Rect rect) {
_textInputConnection
Expand Down
4 changes: 0 additions & 4 deletions lib/src/editor/editor_component/service/keyboard_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import 'package:flutter/material.dart';
/// ```
///
abstract class AppFlowyKeyboardService {
/// Processes shortcut key input.
@Deprecated('Not used anymore')
KeyEventResult onKey(RawKeyEvent event);

/// Enables shortcuts service.
void enable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
_attachTextInputService(selection);
}

@override
KeyEventResult onKey(RawKeyEvent event) => throw UnimplementedError();

@override
Widget build(BuildContext context) {
Widget child = widget.child;
Expand All @@ -145,7 +142,7 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
// the Focus widget is used to handle hardware keyboard.
child = Focus(
focusNode: focusNode,
onKey: _onKey,
onKeyEvent: _onKeyEvent,
child: child,
);
}
Expand All @@ -165,8 +162,9 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
}

/// handle hardware keyboard
KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {
if (event is! RawKeyDownEvent || !enableShortcuts) {
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
if ((event is! KeyDownEvent && event is! KeyRepeatEvent) ||
!enableShortcuts) {
if (textInputService.composingTextRange != TextRange.empty) {
return KeyEventResult.skipRemainingHandlers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ class _MobileScrollServiceState extends State<MobileScrollService>
}

@override
void jumpToTop() {
// TODO: implement jumpToTop
}
void jumpToTop() {}

@override
void jumpToBottom() {
// TODO: implement jumpToBottom
}
void jumpToBottom() {}

@override
void disable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class _DesktopSelectionServiceWidgetState
}

Selection? selection;
if (RawKeyboard.instance.isShiftPressed && _panStartOffset != null) {
if (HardwareKeyboard.instance.isShiftPressed && _panStartOffset != null) {
final first = getNodeInOffset(_panStartOffset!)?.selectable;

if (first != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_event.dart';
import 'package:appflowy_editor/src/editor/command/transform.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_event.dart';
import 'package:appflowy_editor/src/editor/util/util.dart';
import 'package:flutter/services.dart';

Expand All @@ -19,7 +19,8 @@ final CharacterShortcutEvent insertNewLine = CharacterShortcutEvent(
CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async {
// on desktop or web, shift + enter to insert a '\n' character to the same line.
// so, we should return the false to let the system handle it.
if (PlatformExtension.isNotMobile && RawKeyboard.instance.isShiftPressed) {
if (PlatformExtension.isNotMobile &&
HardwareKeyboard.instance.isShiftPressed) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Future<bool> _showSlashMenu(
// show the slash menu
() {
// this code is copied from the the old editor.
// TODO: refactor this code
final context = editorState.getNodeAtPath(selection.start.path)?.context;
if (context != null) {
_selectionMenuService = SelectionMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final CommandShortcutEvent openInlineLinkCommand = CommandShortcutEvent(
KeyEventResult _openInlineLink(
EditorState editorState,
) {
//TODO:If selection is collapsed, isHref is false.
final selection = editorState.selection;
if (selection == null || selection.isCollapsed) {
return KeyEventResult.ignored;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CommandShortcutEvent {
}
}

bool canRespondToRawKeyEvent(RawKeyEvent event) {
bool canRespondToRawKeyEvent(KeyEvent event) {
return keybindings.containsKeyEvent(event);
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/editor/selection_menu/selection_menu_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart';
import 'package:flutter/material.dart';

// TODO: this file is too long, need to refactor.
abstract class SelectionMenuService {
Offset get offset;
Alignment get alignment;
Expand Down
7 changes: 4 additions & 3 deletions lib/src/editor/selection_menu/selection_menu_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class _SelectionMenuWidgetState extends State<SelectionMenuWidget> {
Widget build(BuildContext context) {
return Focus(
focusNode: _focusNode,
onKey: _onKey,
onKeyEvent: _onKeyEvent,
child: DecoratedBox(
decoration: BoxDecoration(
color: widget.selectionMenuStyle.selectionMenuBackgroundColor,
Expand Down Expand Up @@ -382,9 +382,10 @@ class _SelectionMenuWidgetState extends State<SelectionMenuWidget> {
/// Handles arrow keys to switch selected items
/// Handles keyword searches
/// Handles enter to select item and esc to exit
KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
Log.keyboard.debug('slash command, on key $event');
if (event is! RawKeyDownEvent) {

if (event is! KeyDownEvent) {
return KeyEventResult.ignored;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/editor/toolbar/desktop/items/link/link_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class _LinkMenuState extends State<LinkMenu> {
}

Widget _buildInput() {
return RawKeyboardListener(
return KeyboardListener(
focusNode: FocusNode(),
onKey: (key) {
if (key is RawKeyDownEvent &&
onKeyEvent: (key) {
if (key is KeyDownEvent &&
key.logicalKey == LogicalKeyboardKey.escape) {
widget.onDismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class _BackgroundColorOptionsWidgetsState
e.colorHex,
);
});
} else {
// TODO(yijing): handle when no text is selected
}
},
isSelected: isSelected,
Expand Down
11 changes: 0 additions & 11 deletions lib/src/editor/util/raw_keyboard_extension.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/src/editor/util/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export 'delta_util.dart';
export 'editor_state_selectable_extension.dart';
export 'platform_extension.dart';
export 'property_notifier.dart';
export 'raw_keyboard_extension.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class ItemPosition {
final double itemTrailingEdge;

@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType) return false;
final ItemPosition otherPosition = other;
return otherPosition.index == index &&
otherPosition.itemLeadingEdge == itemLeadingEdge &&
otherPosition.itemTrailingEdge == itemTrailingEdge;
bool operator ==(Object other) {
return identical(this, other) ||
(other is ItemPosition &&
other.index == index &&
other.itemLeadingEdge == itemLeadingEdge &&
other.itemTrailingEdge == itemTrailingEdge);
}

@override
Expand Down
14 changes: 8 additions & 6 deletions lib/src/service/shortcut_event/keybinding.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'dart:convert';

import 'package:appflowy_editor/src/service/shortcut_event/key_mapping.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

extension KeybindingsExtension on List<Keybinding> {
bool containsKeyEvent(RawKeyEvent keyEvent) {
bool containsKeyEvent(KeyEvent keyEvent) {
for (final keybinding in this) {
if (keybinding.isMetaPressed == keyEvent.isMetaPressed &&
keybinding.isControlPressed == keyEvent.isControlPressed &&
keybinding.isAltPressed == keyEvent.isAltPressed &&
keybinding.isShiftPressed == keyEvent.isShiftPressed &&
if (keybinding.isMetaPressed == HardwareKeyboard.instance.isMetaPressed &&
keybinding.isControlPressed ==
HardwareKeyboard.instance.isControlPressed &&
keybinding.isAltPressed == HardwareKeyboard.instance.isAltPressed &&
keybinding.isShiftPressed ==
HardwareKeyboard.instance.isShiftPressed &&
keybinding.keyCode == keyEvent.logicalKey.keyId) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/service/shortcut_event/shortcut_event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'package:flutter/material.dart';

typedef ShortcutEventHandler = KeyEventResult Function(
EditorState editorState,
RawKeyEvent? event,
KeyEvent? event,
);
Loading

0 comments on commit 2492b25

Please sign in to comment.