Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: add auto detect language and remove the unused package

Lucas.Xuaf877913d7e8
diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart
index b36cbbd8ac..3949073756 100644
--- a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/code_block_node_widget.dart
+++ b/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, {
diff --git a/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml b/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml
index 432941656d..9f7b4e805b 100644
--- a/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml
+++ b/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:
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart
index 010cbb5840..c04dafe986 100644
--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart
+++ b/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);
}