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:
Lucas 2025-03-18 17:53:21 +08:00 committed by GitHub
parent 22b03eee29
commit a89dd87c16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 36 deletions

View File

@ -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);

View File

@ -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(),
],
),
),
),
);
}

View File

@ -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