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 _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, {

View File

@ -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:

View File

@ -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);
}