mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-06 03:53:02 +00:00
fix: the index error when deleting text and then using the up or down arrow keys (#7009)
This commit is contained in:
parent
e73fd56152
commit
c2743472bc
@ -1,6 +1,5 @@
|
|||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/code_block/code_block_language_selector.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/code_block/code_block_language_selector.dart';
|
||||||
|
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
@ -45,8 +44,10 @@ void main() {
|
|||||||
await onKey(tester, LogicalKeyboardKey.enter);
|
await onKey(tester, LogicalKeyboardKey.enter);
|
||||||
|
|
||||||
final editorState = tester.editor.getCurrentEditorState();
|
final editorState = tester.editor.getCurrentEditorState();
|
||||||
final language =
|
String language = editorState
|
||||||
editorState.getNodeAtPath([0])!.attributes['language'].toString();
|
.getNodeAtPath([0])!
|
||||||
|
.attributes[CodeBlockKeys.language]
|
||||||
|
.toString();
|
||||||
expect(
|
expect(
|
||||||
language.toLowerCase(),
|
language.toLowerCase(),
|
||||||
defaultCodeBlockSupportedLanguages.first.toLowerCase(),
|
defaultCodeBlockSupportedLanguages.first.toLowerCase(),
|
||||||
@ -58,14 +59,29 @@ void main() {
|
|||||||
await onKey(tester, LogicalKeyboardKey.arrowUp);
|
await onKey(tester, LogicalKeyboardKey.arrowUp);
|
||||||
await onKey(tester, LogicalKeyboardKey.enter);
|
await onKey(tester, LogicalKeyboardKey.enter);
|
||||||
|
|
||||||
expect(
|
language = editorState
|
||||||
editorState
|
|
||||||
.getNodeAtPath([0])!
|
.getNodeAtPath([0])!
|
||||||
.attributes['language']
|
.attributes[CodeBlockKeys.language]
|
||||||
.toString()
|
.toString();
|
||||||
.toLowerCase(),
|
expect(
|
||||||
|
language.toLowerCase(),
|
||||||
defaultCodeBlockSupportedLanguages.last.toLowerCase(),
|
defaultCodeBlockSupportedLanguages.last.toLowerCase(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await tester.hoverOnWidget(find.byType(CodeBlockComponentWidget));
|
||||||
|
await tester.tapButtonWithName(language);
|
||||||
|
tester.testTextInput.enterText("rust");
|
||||||
|
await onKey(tester, LogicalKeyboardKey.delete);
|
||||||
|
await onKey(tester, LogicalKeyboardKey.delete);
|
||||||
|
await onKey(tester, LogicalKeyboardKey.arrowDown);
|
||||||
|
tester.testTextInput.enterText("st");
|
||||||
|
await onKey(tester, LogicalKeyboardKey.arrowDown);
|
||||||
|
await onKey(tester, LogicalKeyboardKey.enter);
|
||||||
|
language = editorState
|
||||||
|
.getNodeAtPath([0])!
|
||||||
|
.attributes[CodeBlockKeys.language]
|
||||||
|
.toString();
|
||||||
|
expect(language.toLowerCase(), 'rust');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ class SelectableItemListMenu extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ScrollablePositionedList.builder(
|
return ScrollablePositionedList.builder(
|
||||||
|
physics: const ClampingScrollPhysics(),
|
||||||
shrinkWrap: shrinkWrap,
|
shrinkWrap: shrinkWrap,
|
||||||
itemCount: items.length,
|
itemCount: items.length,
|
||||||
itemScrollController: controller,
|
itemScrollController: controller,
|
||||||
|
|||||||
@ -222,6 +222,9 @@ class _LanguageSelectionPopoverState extends State<_LanguageSelectionPopover> {
|
|||||||
void onArrowKey(AxisDirection direction) {
|
void onArrowKey(AxisDirection direction) {
|
||||||
if (filteredLanguages.isEmpty) return;
|
if (filteredLanguages.isEmpty) return;
|
||||||
final isUp = direction == AxisDirection.up;
|
final isUp = direction == AxisDirection.up;
|
||||||
|
if (selectedIndex < 0) {
|
||||||
|
selectedIndex = isUp ? 0 : -1;
|
||||||
|
}
|
||||||
final length = filteredLanguages.length;
|
final length = filteredLanguages.length;
|
||||||
setState(() {
|
setState(() {
|
||||||
if (isUp) {
|
if (isUp) {
|
||||||
@ -232,6 +235,7 @@ class _LanguageSelectionPopoverState extends State<_LanguageSelectionPopover> {
|
|||||||
});
|
});
|
||||||
languageListController.scrollTo(
|
languageListController.scrollTo(
|
||||||
index: selectedIndex,
|
index: selectedIndex,
|
||||||
|
alignment: 0.5,
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user