Skip to content

Commit a89dd87

Browse files
authored
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
1 parent 22b03ee commit a89dd87

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_shortcuts.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async {
3232
await editorState.deleteSelection(selection);
3333

3434
if (HardwareKeyboard.instance.isShiftPressed) {
35-
await editorState.insertNewLine();
35+
// ignore the shift+enter event, fallback to the default behavior
36+
return false;
3637
} else if (node.children.isEmpty) {
3738
// insert a new paragraph within the callout block
3839
final path = node.path.child(0);

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart

+46-33
Original file line numberDiff line numberDiff line change
@@ -188,52 +188,65 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
188188
onChangeCover: (type, details) =>
189189
_saveIconOrCover(cover: (type, details)),
190190
),
191-
_buildCoverIcon(
192-
context,
193-
constraints,
194-
offset,
195-
),
191+
_buildAlignedCoverIcon(context),
196192
],
197193
),
198-
Padding(
199-
padding: EdgeInsets.fromLTRB(offset, 0, offset, 12),
200-
child: Visibility(
201-
visible: offset != 0,
202-
child: MouseRegion(
203-
onEnter: (event) => isCoverTitleHovered.value = true,
204-
onExit: (event) => isCoverTitleHovered.value = false,
205-
child: CoverTitle(
206-
view: widget.view,
207-
),
208-
),
209-
),
210-
),
194+
_buildAlignedTitle(context),
211195
],
212196
);
213197
},
214198
);
215199
}
216200

217-
Widget _buildCoverIcon(
218-
BuildContext context,
219-
BoxConstraints constraints,
220-
double offset,
221-
) {
222-
if (!hasIcon || offset == 0) {
201+
Widget _buildAlignedTitle(BuildContext context) {
202+
return Center(
203+
child: Container(
204+
constraints: BoxConstraints(
205+
maxWidth: widget.editorState.editorStyle.maxWidth ?? double.infinity,
206+
),
207+
padding: widget.editorState.editorStyle.padding +
208+
const EdgeInsets.symmetric(horizontal: 44),
209+
child: MouseRegion(
210+
onEnter: (event) => isCoverTitleHovered.value = true,
211+
onExit: (event) => isCoverTitleHovered.value = false,
212+
child: CoverTitle(
213+
view: widget.view,
214+
),
215+
),
216+
),
217+
);
218+
}
219+
220+
Widget _buildAlignedCoverIcon(BuildContext context) {
221+
if (!hasIcon) {
223222
return const SizedBox.shrink();
224223
}
225224

226225
return Positioned(
227-
// if hasCover, there shouldn't be icons present so the icon can
228-
// be closer to the bottom.
229-
left: offset,
230226
bottom: hasCover ? kToolbarHeight - kIconHeight / 2 : kToolbarHeight,
231-
child: DocumentIcon(
232-
editorState: widget.editorState,
233-
node: widget.node,
234-
icon: viewIcon,
235-
documentId: view.id,
236-
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
227+
left: 0,
228+
right: 0,
229+
child: Center(
230+
child: Container(
231+
constraints: BoxConstraints(
232+
maxWidth:
233+
widget.editorState.editorStyle.maxWidth ?? double.infinity,
234+
),
235+
padding: widget.editorState.editorStyle.padding +
236+
const EdgeInsets.symmetric(horizontal: 44),
237+
child: Row(
238+
children: [
239+
DocumentIcon(
240+
editorState: widget.editorState,
241+
node: widget.node,
242+
icon: viewIcon,
243+
documentId: view.id,
244+
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
245+
),
246+
Spacer(),
247+
],
248+
),
249+
),
237250
),
238251
);
239252
}

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/quote/quote_block_shortcuts.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ CharacterShortcutEventHandler _insertNewLineHandler = (editorState) async {
3030
await editorState.deleteSelection(selection);
3131

3232
if (HardwareKeyboard.instance.isShiftPressed) {
33-
await editorState.insertNewLine();
34-
return true;
33+
// ignore the shift+enter event, fallback to the default behavior
34+
return false;
3535
} else if (node.children.isEmpty &&
3636
selection.endIndex == node.delta?.length) {
3737
// insert a new paragraph within the callout block

0 commit comments

Comments
 (0)