feat: add auto detect language and remove the unused package

This commit is contained in:
Lucas.Xu 2022-09-27 14:36:40 +08:00
parent 86a6f5827d
commit af877913d7
3 changed files with 7 additions and 6 deletions

View File

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

View File

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

View File

@ -341,12 +341,12 @@ Position? _goUp(EditorState editorState) {
final rect = rects.reduce( final rect = rects.reduce(
(current, next) => current.bottom >= next.bottom ? current : next, (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 { } else {
final rect = rects.reduce( final rect = rects.reduce(
(current, next) => current.top <= next.top ? current : next, (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); return editorState.service.selectionService.getPositionInOffset(offset);
} }
@ -362,12 +362,12 @@ Position? _goDown(EditorState editorState) {
final rect = rects.reduce( final rect = rects.reduce(
(current, next) => current.bottom >= next.bottom ? current : next, (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 { } else {
final rect = rects.reduce( final rect = rects.reduce(
(current, next) => current.top <= next.top ? current : next, (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); return editorState.service.selectionService.getPositionInOffset(offset);
} }