forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support enter to insert new line in callout (AppFlowy-IO#5331)
- Loading branch information
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_shortcuts.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart'; | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
/// Pressing Enter in a callout block will insert a newline (\n) within the callout, | ||
/// while pressing Shift+Enter in a callout will insert a new paragraph next to the callout. | ||
/// | ||
/// - support | ||
/// - desktop | ||
/// - mobile | ||
/// - web | ||
/// | ||
final CharacterShortcutEvent insertNewLineInCalloutBlock = | ||
CharacterShortcutEvent( | ||
key: 'insert a new line in callout block', | ||
character: '\n', | ||
handler: _insertNewLineHandler, | ||
); | ||
|
||
CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async { | ||
final selection = editorState.selection?.normalized; | ||
if (selection == null) { | ||
return false; | ||
} | ||
|
||
final node = editorState.getNodeAtPath(selection.start.path); | ||
if (node == null || node.type != CalloutBlockKeys.type) { | ||
return false; | ||
} | ||
|
||
// delete the selection | ||
await editorState.deleteSelection(selection); | ||
|
||
if (HardwareKeyboard.instance.isShiftPressed) { | ||
await editorState.insertNewLine(); | ||
} else { | ||
await editorState.insertTextAtCurrentSelection('\n'); | ||
} | ||
|
||
return true; | ||
}; |