mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
chore: adjust replace, insert below, discard selection behavior
This commit is contained in:
parent
4997ac99cf
commit
a1c49d6c4e
3 changed files with 20 additions and 4 deletions
|
@ -57,8 +57,13 @@ class AiWriterCubit extends Cubit<AiWriterState> {
|
||||||
bool withDiscard = true,
|
bool withDiscard = true,
|
||||||
bool withUnformat = true,
|
bool withUnformat = true,
|
||||||
}) async {
|
}) async {
|
||||||
|
if (aiWriterNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (withDiscard) {
|
if (withDiscard) {
|
||||||
await _textRobot.discard();
|
await _textRobot.discard(
|
||||||
|
afterSelection: aiWriterNode!.aiWriterSelection,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_textRobot.clear();
|
_textRobot.clear();
|
||||||
_textRobot.reset();
|
_textRobot.reset();
|
||||||
|
@ -232,6 +237,12 @@ class AiWriterCubit extends Cubit<AiWriterState> {
|
||||||
'trigger accept action, markdown text: $trimmedMarkdownText',
|
'trigger accept action, markdown text: $trimmedMarkdownText',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await formatSelection(
|
||||||
|
editorState,
|
||||||
|
selection,
|
||||||
|
ApplySuggestionFormatType.clear,
|
||||||
|
);
|
||||||
|
|
||||||
await _textRobot.deleteAINodes();
|
await _textRobot.deleteAINodes();
|
||||||
|
|
||||||
await _textRobot.replace(
|
await _textRobot.replace(
|
||||||
|
|
|
@ -40,6 +40,7 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {
|
||||||
onRemoveNode: () {
|
onRemoveNode: () {
|
||||||
aiWriterRegistered = false;
|
aiWriterRegistered = false;
|
||||||
widget.editorState.service.keyboardService?.enableShortcuts();
|
widget.editorState.service.keyboardService?.enableShortcuts();
|
||||||
|
widget.editorState.service.keyboardService?.enable();
|
||||||
},
|
},
|
||||||
onAppendToDocument: onAppendToDocument,
|
onAppendToDocument: onAppendToDocument,
|
||||||
);
|
);
|
||||||
|
|
|
@ -118,7 +118,7 @@ class MarkdownTextRobot {
|
||||||
}
|
}
|
||||||
|
|
||||||
await _lock.synchronized(() async {
|
await _lock.synchronized(() async {
|
||||||
await _refresh(inMemoryUpdate: false);
|
await _refresh(inMemoryUpdate: false, updateSelection: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_enableDebug) {
|
if (_enableDebug) {
|
||||||
|
@ -156,7 +156,9 @@ class MarkdownTextRobot {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discard the inserted content
|
/// Discard the inserted content
|
||||||
Future<void> discard() async {
|
Future<void> discard({
|
||||||
|
Selection? afterSelection,
|
||||||
|
}) async {
|
||||||
final start = _insertPosition;
|
final start = _insertPosition;
|
||||||
if (start == null) {
|
if (start == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -165,6 +167,8 @@ class MarkdownTextRobot {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterSelection ??= Selection.collapsed(start);
|
||||||
|
|
||||||
// fallback to the calculated position if the selection is null.
|
// fallback to the calculated position if the selection is null.
|
||||||
final end = Position(
|
final end = Position(
|
||||||
path: start.path.nextNPath(_insertedNodes.length - 1),
|
path: start.path.nextNPath(_insertedNodes.length - 1),
|
||||||
|
@ -174,7 +178,7 @@ class MarkdownTextRobot {
|
||||||
);
|
);
|
||||||
final transaction = editorState.transaction
|
final transaction = editorState.transaction
|
||||||
..deleteNodes(deletedNodes)
|
..deleteNodes(deletedNodes)
|
||||||
..afterSelection = Selection.collapsed(start);
|
..afterSelection = afterSelection;
|
||||||
|
|
||||||
await editorState.apply(
|
await editorState.apply(
|
||||||
transaction,
|
transaction,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue