Skip to content

Commit

Permalink
fix: empty items disable context menu (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed May 10, 2024
1 parent b827d08 commit 1ceed9b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion example/windows/flutter/CMakeLists.txt
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/src/editor/editor_component/service/editor.dart
Expand Up @@ -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
///
Expand Down
Expand Up @@ -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() =>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -394,7 +399,7 @@ class _DesktopSelectionServiceWidgetState
builder: (context) => ContextMenu(
position: offset,
editorState: editorState,
items: widget.contextMenuItems,
items: widget.contextMenuItems!,
onPressed: () => _clearContextMenu(),
),
);
Expand Down
Expand Up @@ -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.
///
Expand Down

0 comments on commit 1ceed9b

Please sign in to comment.