mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-28 07:33:45 +00:00
fix: optimize cover title position offset calculation (#7568)
* fix: optimize cover title position offset calculation * feat: ingore shift+enter in callout/quote and fallback to system behavior
This commit is contained in:
parent
22b03eee29
commit
a89dd87c16
@ -32,7 +32,8 @@ CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async {
|
||||
await editorState.deleteSelection(selection);
|
||||
|
||||
if (HardwareKeyboard.instance.isShiftPressed) {
|
||||
await editorState.insertNewLine();
|
||||
// ignore the shift+enter event, fallback to the default behavior
|
||||
return false;
|
||||
} else if (node.children.isEmpty) {
|
||||
// insert a new paragraph within the callout block
|
||||
final path = node.path.child(0);
|
||||
|
||||
@ -188,52 +188,65 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
|
||||
onChangeCover: (type, details) =>
|
||||
_saveIconOrCover(cover: (type, details)),
|
||||
),
|
||||
_buildCoverIcon(
|
||||
context,
|
||||
constraints,
|
||||
offset,
|
||||
),
|
||||
_buildAlignedCoverIcon(context),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(offset, 0, offset, 12),
|
||||
child: Visibility(
|
||||
visible: offset != 0,
|
||||
child: MouseRegion(
|
||||
onEnter: (event) => isCoverTitleHovered.value = true,
|
||||
onExit: (event) => isCoverTitleHovered.value = false,
|
||||
child: CoverTitle(
|
||||
view: widget.view,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildAlignedTitle(context),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCoverIcon(
|
||||
BuildContext context,
|
||||
BoxConstraints constraints,
|
||||
double offset,
|
||||
) {
|
||||
if (!hasIcon || offset == 0) {
|
||||
Widget _buildAlignedTitle(BuildContext context) {
|
||||
return Center(
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: widget.editorState.editorStyle.maxWidth ?? double.infinity,
|
||||
),
|
||||
padding: widget.editorState.editorStyle.padding +
|
||||
const EdgeInsets.symmetric(horizontal: 44),
|
||||
child: MouseRegion(
|
||||
onEnter: (event) => isCoverTitleHovered.value = true,
|
||||
onExit: (event) => isCoverTitleHovered.value = false,
|
||||
child: CoverTitle(
|
||||
view: widget.view,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAlignedCoverIcon(BuildContext context) {
|
||||
if (!hasIcon) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Positioned(
|
||||
// if hasCover, there shouldn't be icons present so the icon can
|
||||
// be closer to the bottom.
|
||||
left: offset,
|
||||
bottom: hasCover ? kToolbarHeight - kIconHeight / 2 : kToolbarHeight,
|
||||
child: DocumentIcon(
|
||||
editorState: widget.editorState,
|
||||
node: widget.node,
|
||||
icon: viewIcon,
|
||||
documentId: view.id,
|
||||
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth:
|
||||
widget.editorState.editorStyle.maxWidth ?? double.infinity,
|
||||
),
|
||||
padding: widget.editorState.editorStyle.padding +
|
||||
const EdgeInsets.symmetric(horizontal: 44),
|
||||
child: Row(
|
||||
children: [
|
||||
DocumentIcon(
|
||||
editorState: widget.editorState,
|
||||
node: widget.node,
|
||||
icon: viewIcon,
|
||||
documentId: view.id,
|
||||
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
|
||||
),
|
||||
Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -30,8 +30,8 @@ CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async {
|
||||
await editorState.deleteSelection(selection);
|
||||
|
||||
if (HardwareKeyboard.instance.isShiftPressed) {
|
||||
await editorState.insertNewLine();
|
||||
return true;
|
||||
// ignore the shift+enter event, fallback to the default behavior
|
||||
return false;
|
||||
} else if (node.children.isEmpty &&
|
||||
selection.endIndex == node.delta?.length) {
|
||||
// insert a new paragraph within the callout block
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user