fix: empty items disable context menu (#793)

This commit is contained in:
Mathias Mogensen 2024-05-10 16:41:07 +02:00 • committed by GitHub
commit 1ceed9b4d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View file

@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()
# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS

View file

@ -117,9 +117,13 @@ class AppFlowyEditor extends StatefulWidget {
/// The context menu items.
///
/// They will be shown when the user right click on the editor.
/// Each item will be separated by a divider.
///
/// A divider will be added between each list.
final List<List<ContextMenuItem>> contextMenuItems;
/// Defaults to [standardContextMenuItems].
///
/// If empty the context menu won't appear.
///
final List<List<ContextMenuItem>>? contextMenuItems;
/// Provide a editorScrollController to control the scroll behavior
///

View file

@ -14,14 +14,14 @@ class DesktopSelectionServiceWidget extends StatefulWidget {
super.key,
this.cursorColor = const Color(0xFF00BCF0),
this.selectionColor = const Color(0xFF00BCF0),
required this.contextMenuItems,
this.contextMenuItems,
required this.child,
});
final Widget child;
final Color cursorColor;
final Color selectionColor;
final List<List<ContextMenuItem>> contextMenuItems;
final List<List<ContextMenuItem>>? contextMenuItems;
@override
State<DesktopSelectionServiceWidget> createState() =>
@ -363,6 +363,11 @@ class _DesktopSelectionServiceWidgetState
void _showContextMenu(TapDownDetails details) {
_clearContextMenu();
// Don't trigger the context menu if there are no items
if (widget.contextMenuItems == null || widget.contextMenuItems!.isEmpty) {
return;
}
// only shows around the selection area.
if (selectionRects.isEmpty) {
return;
@ -394,7 +399,7 @@ class _DesktopSelectionServiceWidgetState
builder: (context) => ContextMenu(
position: offset,
editorState: editorState,
items: widget.contextMenuItems,
items: widget.contextMenuItems!,
onPressed: () => _clearContextMenu(),
),
);

View file

@ -10,14 +10,14 @@ class SelectionServiceWidget extends StatefulWidget {
this.cursorColor = const Color(0xFF00BCF0),
this.selectionColor = const Color.fromARGB(53, 111, 201, 231),
this.showMagnifier = true,
required this.contextMenuItems,
this.contextMenuItems,
required this.child,
});
final Widget child;
final Color cursorColor;
final Color selectionColor;
final List<List<ContextMenuItem>> contextMenuItems;
final List<List<ContextMenuItem>>? contextMenuItems;
/// Show the magnifier or not.
///