mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-11-10 10:18:57 +03:00
chore: delete unused code
This commit is contained in:
parent
c643c02887
commit
34a1da8450
@ -33,8 +33,7 @@ class _ImageNodeWidget extends StatefulWidget {
|
||||
State<_ImageNodeWidget> createState() => __ImageNodeWidgetState();
|
||||
}
|
||||
|
||||
class __ImageNodeWidgetState extends State<_ImageNodeWidget>
|
||||
with Selectable, KeyboardEventsRespondable {
|
||||
class __ImageNodeWidgetState extends State<_ImageNodeWidget> with Selectable {
|
||||
Node get node => widget.node;
|
||||
EditorState get editorState => widget.editorState;
|
||||
String get src => widget.node.attributes['image_src'] as String;
|
||||
@ -62,17 +61,6 @@ class __ImageNodeWidgetState extends State<_ImageNodeWidget>
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
KeyEventResult onKeyDown(RawKeyEvent event) {
|
||||
if (event.logicalKey == LogicalKeyboardKey.backspace) {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteNode(node)
|
||||
..commit();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _build(context);
|
||||
|
@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class SelectedTextNodeBuilder extends NodeWidgetBuilder {
|
||||
@ -20,7 +19,6 @@ class SelectedTextNodeBuilder extends NodeWidgetBuilder {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext buildContext) {
|
||||
print('key -> $key');
|
||||
return _SelectedTextNodeWidget(
|
||||
key: key,
|
||||
node: node,
|
||||
@ -45,7 +43,7 @@ class _SelectedTextNodeWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
||||
with Selectable, KeyboardEventsRespondable {
|
||||
with Selectable {
|
||||
TextNode get node => widget.node as TextNode;
|
||||
EditorState get editorState => widget.editorState;
|
||||
|
||||
@ -99,39 +97,6 @@ class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
||||
return _textSelection;
|
||||
}
|
||||
|
||||
@override
|
||||
KeyEventResult onKeyDown(RawKeyEvent event) {
|
||||
if (event.logicalKey == LogicalKeyboardKey.backspace) {
|
||||
final textSelection = _textSelection;
|
||||
// TODO: just handle upforward delete.
|
||||
if (textSelection != null) {
|
||||
if (textSelection.isCollapsed) {
|
||||
print(node.toRawString());
|
||||
print('is empty ${node.toRawString().isEmpty}');
|
||||
if (textSelection.baseOffset == 0 && node.toRawString().isEmpty) {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteNode(node)
|
||||
..commit();
|
||||
} else {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteText(node, textSelection.start - 1, 1)
|
||||
..commit();
|
||||
// final rect = _computeCursorRect(textSelection.baseOffset - 1);
|
||||
// editorState.tapOffset = rect.center;
|
||||
// editorState.updateCursor();
|
||||
}
|
||||
} else {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteText(node, textSelection.start,
|
||||
textSelection.baseOffset - textSelection.extentOffset)
|
||||
..commit();
|
||||
}
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('text rebuild $this');
|
||||
|
@ -1,9 +1,5 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flowy_editor/document/node.dart';
|
||||
import 'package:flowy_editor/keyboard.dart';
|
||||
import 'package:flowy_editor/operation/operation.dart';
|
||||
import 'package:flowy_editor/render/selectable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './document/state_tree.dart';
|
||||
@ -26,14 +22,11 @@ class EditorState {
|
||||
|
||||
/// TODO: move to a better place.
|
||||
Widget build(BuildContext context) {
|
||||
return Keyboard(
|
||||
editorState: this,
|
||||
child: renderPlugins.buildWidget(
|
||||
context: NodeWidgetContext(
|
||||
buildContext: context,
|
||||
node: document.root,
|
||||
editorState: this,
|
||||
),
|
||||
return renderPlugins.buildWidget(
|
||||
context: NodeWidgetContext(
|
||||
buildContext: context,
|
||||
node: document.root,
|
||||
editorState: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
import '../render/selectable.dart';
|
||||
import 'editor_state.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Keyboard extends StatelessWidget {
|
||||
final Widget child;
|
||||
final focusNode = FocusNode();
|
||||
final EditorState editorState;
|
||||
|
||||
Keyboard({
|
||||
Key? key,
|
||||
required this.child,
|
||||
required this.editorState,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Focus(
|
||||
focusNode: focusNode,
|
||||
autofocus: true,
|
||||
onKey: _onKey,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {
|
||||
// if (event is! RawKeyDownEvent) {
|
||||
// return KeyEventResult.ignored;
|
||||
// }
|
||||
// List<KeyEventResult> result = [];
|
||||
// for (final node in editorState.selectedNodes) {
|
||||
// if (node.key != null &&
|
||||
// node.key?.currentState is KeyboardEventsRespondable) {
|
||||
// final respondable = node.key!.currentState as KeyboardEventsRespondable;
|
||||
// result.add(respondable.onKeyDown(event));
|
||||
// }
|
||||
// }
|
||||
// if (result.contains(KeyEventResult.handled)) {
|
||||
// return KeyEventResult.handled;
|
||||
// }
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
}
|
@ -51,7 +51,6 @@ class RenderPlugins {
|
||||
_nodeWidgetBuilders.removeWhere((key, _) => key == name);
|
||||
}
|
||||
|
||||
@protected
|
||||
Widget buildWidget({
|
||||
required NodeWidgetContext context,
|
||||
bool withSubtype = true,
|
||||
|
@ -12,7 +12,3 @@ mixin Selectable<T extends StatefulWidget> on State<T> {
|
||||
/// For [TextNode] only.
|
||||
TextSelection? getTextSelection();
|
||||
}
|
||||
|
||||
mixin KeyboardEventsRespondable<T extends StatefulWidget> on State<T> {
|
||||
KeyEventResult onKeyDown(RawKeyEvent event);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user