Skip to content

Commit

Permalink
fix: turn into issues (AppFlowy-IO#6576)
Browse files Browse the repository at this point in the history
* fix: cover title issues

* fix: the selection should be cleared if selecting child node

* fix: exclude the blocks that are not supported in the 'turn into' types

* fix: add logs

* fix: floating toolbar ai status

* test: selecting the parent should deselect all the child nodes as well

* chore: 'Copy Link' to 'Copy link'

* fix: select all and turn into block doesn't work on Windows

* test: calculate turn into selection test

* fix: option button tests
  • Loading branch information
LucasXu0 authored Oct 18, 2024
1 parent ec40894 commit 7b031b2
Show file tree
Hide file tree
Showing 12 changed files with 661 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand Down Expand Up @@ -143,5 +144,37 @@ void main() {
);
}
});

testWidgets(
'selecting the parent should deselect all the child nodes as well',
(tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();

const name = 'Test Document';
await tester.createNewPageWithNameUnderParent(name: name);
await tester.openPage(name);

// create a nested list
// Item 1
// Nested Item 1
await tester.editor.tapLineOfEditorAt(0);
await tester.ime.insertText('Item 1');
await tester.ime.insertCharacter('\n');
await tester.simulateKeyEvent(LogicalKeyboardKey.tab);
await tester.ime.insertText('Nested Item 1');

// select the 'Nested Item 1' and then tap the option button of the 'Item 1'
final editorState = tester.editor.getCurrentEditorState();
final selection = Selection.collapsed(
Position(path: [0, 0], offset: 1),
);
editorState.selection = selection;
await tester.pumpAndSettle();
expect(editorState.selection, selection);
await tester.editor.hoverAndClickOptionMenuButton([0]);
expect(editorState.selection, Selection.collapsed(Position(path: [0])));
},
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'document_create_and_delete_test.dart'
import 'document_inline_page_reference_test.dart'
as document_inline_page_reference_test;
import 'document_more_actions_test.dart' as document_more_actions_test;
import 'document_option_action_test.dart' as document_option_action_test;
import 'document_shortcuts_test.dart' as document_shortcuts_test;
import 'document_text_direction_test.dart' as document_text_direction_test;
import 'document_with_cover_image_test.dart' as document_with_cover_image_test;
Expand Down Expand Up @@ -40,7 +39,6 @@ void main() {
document_codeblock_paste_test.main();
document_alignment_test.main();
document_text_direction_test.main();
document_option_action_test.main();
document_with_image_block_test.main();
document_with_multi_image_block_test.main();
document_inline_page_reference_test.main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {
);
insertedNode.add(afterNode);
insertedNode.addAll(node.children.map((e) => e.copyWith()));
} else if (!EditorOptionActionType.turnInto.supportTypes
.contains(node.type)) {
afterNode = node.copyWith();
insertedNode.add(afterNode);
} else {
insertedNode.add(afterNode);
}
Expand All @@ -267,4 +271,35 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {

return true;
}

Selection? calculateTurnIntoSelection(
Node selectedNode,
Selection? beforeSelection,
) {
final path = selectedNode.path;
final selection = Selection.collapsed(
Position(path: path),
);

// if the previous selection is null or the start path is not in the same level as the current block path,
// then update the selection with the current block path
// for example,'|' means the selection,
// case 1: collapsed selection
// - bulleted item 1
// - bulleted |item 2
// when clicking the bulleted item 1, the bulleted item 1 path should be selected
// case 2: not collapsed selection
// - bulleted item 1
// - bulleted |item 2
// - bulleted |item 3
// when clicking the bulleted item 1, the bulleted item 1 path should be selected
if (beforeSelection == null ||
beforeSelection.start.path.length != path.length ||
!path.inSelection(beforeSelection)) {
return selection;
}
// if the beforeSelection start with the current block,
// then updating the selection with the beforeSelection that may contains multiple blocks
return beforeSelection;
}
}
Loading

0 comments on commit 7b031b2

Please sign in to comment.