mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: alt+click to add block above (#2988)
This commit is contained in:
@ -0,0 +1,11 @@
|
|||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
extension RawKeyboardExtension on RawKeyboard {
|
||||||
|
bool get isAltPressed => keysPressed.any(
|
||||||
|
(key) => [
|
||||||
|
LogicalKeyboardKey.alt,
|
||||||
|
LogicalKeyboardKey.altLeft,
|
||||||
|
LogicalKeyboardKey.altRight,
|
||||||
|
].contains(key),
|
||||||
|
);
|
||||||
|
}
|
@ -312,7 +312,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
|||||||
builder.actionBuilder = (context, state) {
|
builder.actionBuilder = (context, state) {
|
||||||
final padding = context.node.type == HeadingBlockKeys.type
|
final padding = context.node.type == HeadingBlockKeys.type
|
||||||
? const EdgeInsets.only(top: 8.0)
|
? const EdgeInsets.only(top: 8.0)
|
||||||
: const EdgeInsets.all(0);
|
: EdgeInsets.zero;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: padding,
|
padding: padding,
|
||||||
child: BlockActionList(
|
child: BlockActionList(
|
||||||
@ -320,9 +320,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
|||||||
blockComponentState: state,
|
blockComponentState: state,
|
||||||
editorState: widget.editorState,
|
editorState: widget.editorState,
|
||||||
actions: actions,
|
actions: actions,
|
||||||
showSlashMenu: () => showSlashMenu(
|
showSlashMenu: () => showSlashMenu(widget.editorState),
|
||||||
widget.editorState,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:appflowy/core/raw_keyboard_extension.dart';
|
||||||
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_button.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_button.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class BlockAddButton extends StatelessWidget {
|
class BlockAddButton extends StatelessWidget {
|
||||||
const BlockAddButton({
|
const BlockAddButton({
|
||||||
@ -21,25 +27,41 @@ class BlockAddButton extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlockActionButton(
|
return BlockActionButton(
|
||||||
svgName: 'editor/add',
|
svgName: 'editor/add',
|
||||||
richMessage: const TextSpan(
|
richMessage: TextSpan(
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
// todo: l10n.
|
text: LocaleKeys.blockActions_addBelowTooltip.tr(),
|
||||||
text: 'Click to add below',
|
),
|
||||||
|
const TextSpan(text: '\n'),
|
||||||
|
TextSpan(
|
||||||
|
text: Platform.isMacOS
|
||||||
|
? LocaleKeys.blockActions_addAboveMacCmd.tr()
|
||||||
|
: LocaleKeys.blockActions_addAboveCmd.tr(),
|
||||||
|
),
|
||||||
|
const TextSpan(text: ' '),
|
||||||
|
TextSpan(
|
||||||
|
text: LocaleKeys.blockActions_addAboveTooltip.tr(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
final isAltPressed = RawKeyboard.instance.isAltPressed;
|
||||||
|
|
||||||
final transaction = editorState.transaction;
|
final transaction = editorState.transaction;
|
||||||
// if the current block is not a empty paragraph block, then insert a new block below the current block.
|
|
||||||
|
// If the current block is not an empty paragraph block,
|
||||||
|
// then insert a new block above/below the current block.
|
||||||
final node = blockComponentContext.node;
|
final node = blockComponentContext.node;
|
||||||
if (node.type != ParagraphBlockKeys.type ||
|
if (node.type != ParagraphBlockKeys.type ||
|
||||||
(node.delta?.isNotEmpty ?? true)) {
|
(node.delta?.isNotEmpty ?? true)) {
|
||||||
transaction.insertNode(node.path.next, paragraphNode());
|
final path = isAltPressed ? node.path : node.path.next;
|
||||||
transaction.afterSelection = Selection.collapse(node.path.next, 0);
|
|
||||||
|
transaction.insertNode(path, paragraphNode());
|
||||||
|
transaction.afterSelection = Selection.collapse(path, 0);
|
||||||
} else {
|
} else {
|
||||||
transaction.afterSelection = Selection.collapse(node.path, 0);
|
transaction.afterSelection = Selection.collapse(node.path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the slash menu.
|
// show the slash menu.
|
||||||
editorState.apply(transaction).then(
|
editorState.apply(transaction).then(
|
||||||
(_) => WidgetsBinding.instance.addPostFrameCallback(
|
(_) => WidgetsBinding.instance.addPostFrameCallback(
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
"title": "Title",
|
"title": "Title",
|
||||||
"youCanAlso": "You can also",
|
"youCanAlso": "You can also",
|
||||||
"and": "and",
|
"and": "and",
|
||||||
|
"blockActions": {
|
||||||
|
"addBelowTooltip": "Click to add below",
|
||||||
|
"addAboveCmd": "Alt+click",
|
||||||
|
"addAboveMacCmd": "Option+click",
|
||||||
|
"addAboveTooltip": "to add above"
|
||||||
|
},
|
||||||
"signUp": {
|
"signUp": {
|
||||||
"buttonText": "Sign Up",
|
"buttonText": "Sign Up",
|
||||||
"title": "Sign Up to @:appName",
|
"title": "Sign Up to @:appName",
|
||||||
|
Reference in New Issue
Block a user