Skip to content

Commit bcb1e8e

Browse files
authored
chore: adjust replace, insert below, discard selection behavior (#7719)
1 parent 4997ac9 commit bcb1e8e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_cubit.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ class AiWriterCubit extends Cubit<AiWriterState> {
5757
bool withDiscard = true,
5858
bool withUnformat = true,
5959
}) async {
60+
if (aiWriterNode == null) {
61+
return;
62+
}
6063
if (withDiscard) {
61-
await _textRobot.discard();
64+
await _textRobot.discard(
65+
afterSelection: aiWriterNode!.aiWriterSelection,
66+
);
6267
}
6368
_textRobot.clear();
6469
_textRobot.reset();
@@ -232,6 +237,12 @@ class AiWriterCubit extends Cubit<AiWriterState> {
232237
'trigger accept action, markdown text: $trimmedMarkdownText',
233238
);
234239

240+
await formatSelection(
241+
editorState,
242+
selection,
243+
ApplySuggestionFormatType.clear,
244+
);
245+
235246
await _textRobot.deleteAINodes();
236247

237248
await _textRobot.replace(

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_scroll_wrapper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {
4040
onRemoveNode: () {
4141
aiWriterRegistered = false;
4242
widget.editorState.service.keyboardService?.enableShortcuts();
43+
widget.editorState.service.keyboardService?.enable();
4344
},
4445
onAppendToDocument: onAppendToDocument,
4546
);

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MarkdownTextRobot {
118118
}
119119

120120
await _lock.synchronized(() async {
121-
await _refresh(inMemoryUpdate: false);
121+
await _refresh(inMemoryUpdate: false, updateSelection: true);
122122
});
123123

124124
if (_enableDebug) {
@@ -156,7 +156,9 @@ class MarkdownTextRobot {
156156
}
157157

158158
/// Discard the inserted content
159-
Future<void> discard() async {
159+
Future<void> discard({
160+
Selection? afterSelection,
161+
}) async {
160162
final start = _insertPosition;
161163
if (start == null) {
162164
return;
@@ -165,6 +167,8 @@ class MarkdownTextRobot {
165167
return;
166168
}
167169

170+
afterSelection ??= Selection.collapsed(start);
171+
168172
// fallback to the calculated position if the selection is null.
169173
final end = Position(
170174
path: start.path.nextNPath(_insertedNodes.length - 1),
@@ -174,7 +178,7 @@ class MarkdownTextRobot {
174178
);
175179
final transaction = editorState.transaction
176180
..deleteNodes(deletedNodes)
177-
..afterSelection = Selection.collapsed(start);
181+
..afterSelection = afterSelection;
178182

179183
await editorState.apply(
180184
transaction,

0 commit comments

Comments
 (0)