Переглянути джерело

feat: add auto detect language and remove the unused package

Lucas.Xu 2 роки тому
батько
коміт
af877913d7

+ 3 - 1
frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart

@@ -121,6 +121,7 @@ class __CodeBlockNodeWidgeState extends State<_CodeBlockNodeWidge>
   final _richTextKey = GlobalKey(debugLabel: 'code_block_text');
   final _padding = const EdgeInsets.only(left: 20, top: 20, bottom: 20);
   String? get _language => widget.textNode.attributes['language'] as String?;
+  String? _detectLanguage;
 
   @override
   SelectableMixin<StatefulWidget> get forward =>
@@ -148,6 +149,7 @@ class __CodeBlockNodeWidgeState extends State<_CodeBlockNodeWidge>
       language: _language,
       autoDetection: _language == null,
     );
+    _detectLanguage = _language ?? result.language;
     final code = result.nodes;
     final codeTextSpan = _convert(code!);
     return Container(
@@ -174,7 +176,7 @@ class __CodeBlockNodeWidgeState extends State<_CodeBlockNodeWidge>
       top: -5,
       right: 0,
       child: DropdownButton<String>(
-        value: _language,
+        value: _detectLanguage,
         onChanged: (value) {
           TransactionBuilder(widget.editorState)
             ..updateNode(widget.textNode, {

+ 0 - 1
frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml

@@ -44,7 +44,6 @@ dependencies:
   file_picker: ^5.0.1
   universal_html: ^2.0.8
   highlight: ^0.7.0
-  flutter_highlight: ^0.7.0
 
 dev_dependencies:
   flutter_test:

+ 4 - 4
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart

@@ -341,12 +341,12 @@ Position? _goUp(EditorState editorState) {
     final rect = rects.reduce(
       (current, next) => current.bottom >= next.bottom ? current : next,
     );
-    offset = rect.topRight.translate(0, -rect.height * 1.3);
+    offset = rect.topRight.translate(0, -rect.height);
   } else {
     final rect = rects.reduce(
       (current, next) => current.top <= next.top ? current : next,
     );
-    offset = rect.topLeft.translate(0, -rect.height * 1.3);
+    offset = rect.topLeft.translate(0, -rect.height);
   }
   return editorState.service.selectionService.getPositionInOffset(offset);
 }
@@ -362,12 +362,12 @@ Position? _goDown(EditorState editorState) {
     final rect = rects.reduce(
       (current, next) => current.bottom >= next.bottom ? current : next,
     );
-    offset = rect.bottomRight.translate(0, rect.height * 1.3);
+    offset = rect.bottomRight.translate(0, rect.height);
   } else {
     final rect = rects.reduce(
       (current, next) => current.top <= next.top ? current : next,
     );
-    offset = rect.bottomLeft.translate(0, rect.height * 1.3);
+    offset = rect.bottomLeft.translate(0, rect.height);
   }
   return editorState.service.selectionService.getPositionInOffset(offset);
 }