Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the magnifier doesn't disappear when the selection is collapsed #675

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

enum MobileSelectionDragMode {
none,
leftSelectionHandler,
rightSelectionHandler,
leftSelectionHandle,
rightSelectionHandle,
cursor;
}

enum MobileSelectionHandlerType {
leftHandler,
rightHandler,
cursorHandler,
leftHandle,
rightHandle,
cursorHandle,
}

// the value type is MobileSelectionDragMode
Expand Down Expand Up @@ -165,6 +165,14 @@
return const SizedBox.shrink();
}

if (selection.isCollapsed &&
[

Check warning on line 169 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L168-L169

Added lines #L168 - L169 were not covered by tests
MobileSelectionDragMode.leftSelectionHandle,
MobileSelectionDragMode.rightSelectionHandle,
].contains(dragMode)) {

Check warning on line 172 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L172

Added line #L172 was not covered by tests
return const SizedBox.shrink();
}

selection = selection.normalized;

final node = editorState.getNodeAtPath(selection.start.path);
Expand Down Expand Up @@ -208,10 +216,24 @@
return ValueListenableBuilder(
valueListenable: selectionNotifierAfterLayout,
builder: (context, selection, _) {
if (selection == null || selection.isCollapsed) {
if (selection == null) {
return const SizedBox.shrink();
}

if (selection.isCollapsed &&
[

Check warning on line 224 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L223-L224

Added lines #L223 - L224 were not covered by tests
MobileSelectionDragMode.none,
MobileSelectionDragMode.cursor,
].contains(dragMode)) {

Check warning on line 227 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L227

Added line #L227 was not covered by tests
return const SizedBox.shrink();
}

final isCollapsedWhenDraggingHandle = selection.isCollapsed &&
[

Check warning on line 232 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L231-L232

Added lines #L231 - L232 were not covered by tests
MobileSelectionDragMode.leftSelectionHandle,
MobileSelectionDragMode.rightSelectionHandle,
].contains(dragMode);

Check warning on line 235 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L235

Added line #L235 was not covered by tests

selection = selection.normalized;

final node = editorState.getNodeAtPath(
Expand All @@ -220,10 +242,20 @@
: selection.end.path,
);
final selectable = node?.selectable;
final rects = selectable?.getRectsInSelection(
selection,
shiftWithBaseOffset: true,
);

// get the cursor rect when the selection is collapsed.
final rects = isCollapsedWhenDraggingHandle
? [
selectable?.getCursorRectInPosition(
selection.start,

Check warning on line 250 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L248-L250

Added lines #L248 - L250 were not covered by tests
shiftWithBaseOffset: true,
) ??
Rect.zero,
]
: selectable?.getRectsInSelection(

Check warning on line 255 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L255

Added line #L255 was not covered by tests
selection,
shiftWithBaseOffset: true,
);

if (node == null || rects == null || rects.isEmpty) {
return const SizedBox.shrink();
Expand All @@ -234,7 +266,9 @@
layerLink: node.layerLink,
rect: handleType == HandleType.left ? rects.first : rects.last,
handleType: handleType,
handleColor: editorStyle.dragHandleColor,
handleColor: isCollapsedWhenDraggingHandle
? Colors.transparent
: editorStyle.dragHandleColor,

Check warning on line 271 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L271

Added line #L271 was not covered by tests
handleWidth: editorStyle.mobileDragHandleWidth,
handleBallWidth: editorStyle.mobileDragHandleBallSize.width,
enableHapticFeedbackOnAndroid:
Expand Down Expand Up @@ -276,6 +310,7 @@
void clearSelection() {
currentSelectedNodes = [];
currentSelection.value = null;
_lastPanOffset.value = null;

_clearSelection();
}
Expand Down Expand Up @@ -470,12 +505,12 @@
Selection? newSelection;

if (end != null) {
if (dragMode == MobileSelectionDragMode.leftSelectionHandler) {
if (dragMode == MobileSelectionDragMode.leftSelectionHandle) {

Check warning on line 508 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L508

Added line #L508 was not covered by tests
newSelection = Selection(
start: _panStartSelection!.normalized.end,
end: end,
).normalized;
} else if (dragMode == MobileSelectionDragMode.rightSelectionHandler) {
} else if (dragMode == MobileSelectionDragMode.rightSelectionHandle) {

Check warning on line 513 in lib/src/editor/editor_component/service/selection/mobile_selection_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/editor_component/service/selection/mobile_selection_service.dart#L513

Added line #L513 was not covered by tests
newSelection = Selection(
start: _panStartSelection!.normalized.start,
end: end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class _MobileFloatingToolbarState extends State<MobileFloatingToolbar>
_clear();
final dragMode = editorState.selectionExtraInfo?[selectionDragModeKey];
if ([
MobileSelectionDragMode.leftSelectionHandler,
MobileSelectionDragMode.rightSelectionHandler,
MobileSelectionDragMode.leftSelectionHandle,
MobileSelectionDragMode.rightSelectionHandle,
].contains(dragMode)) {
return;
}
Expand Down
14 changes: 10 additions & 4 deletions lib/src/render/selection/mobile_basic_handle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
case HandleType.none:
throw UnsupportedError('Unsupported handle type');
case HandleType.left:
return MobileSelectionDragMode.leftSelectionHandler;
return MobileSelectionDragMode.leftSelectionHandle;
case HandleType.right:
return MobileSelectionDragMode.rightSelectionHandler;
return MobileSelectionDragMode.rightSelectionHandle;
case HandleType.collapsed:
return MobileSelectionDragMode.cursor;
}
Expand Down Expand Up @@ -207,19 +207,25 @@

final editorState = context.read<EditorState>();
final ballWidth = handleBallWidth;
double offset = 0.0;
if (handleType == HandleType.left) {

Check warning on line 211 in lib/src/render/selection/mobile_basic_handle.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/render/selection/mobile_basic_handle.dart#L211

Added line #L211 was not covered by tests
offset = ballWidth;
} else if (handleType == HandleType.right) {
offset = -ballWidth;

Check warning on line 214 in lib/src/render/selection/mobile_basic_handle.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/render/selection/mobile_basic_handle.dart#L213-L214

Added lines #L213 - L214 were not covered by tests
}

child = GestureDetector(
behavior: HitTestBehavior.opaque,
dragStartBehavior: DragStartBehavior.down,
onPanStart: (details) {
editorState.service.selectionService.onPanStart(
details.translate(0, -ballWidth),
details.translate(0, offset),

Check warning on line 222 in lib/src/render/selection/mobile_basic_handle.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/render/selection/mobile_basic_handle.dart#L222

Added line #L222 was not covered by tests
handleType.dragMode,
);
},
onPanUpdate: (details) {
editorState.service.selectionService.onPanUpdate(
details.translate(0, -ballWidth),
details.translate(0, offset),

Check warning on line 228 in lib/src/render/selection/mobile_basic_handle.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/render/selection/mobile_basic_handle.dart#L228

Added line #L228 was not covered by tests
handleType.dragMode,
);
},
Expand Down
Loading