Unverified Commit 33e261c0 authored by Tomasz Gucio's avatar Tomasz Gucio Committed by GitHub

Update clipboard status on cut (#92167)

Cut now explicitly updates the clipboard status.
parent 88652122
......@@ -55,7 +55,7 @@ class _CupertinoDesktopTextSelectionControls extends TextSelectionControls {
clipboardStatus: clipboardStatus,
endpoints: endpoints,
globalEditableRegion: globalEditableRegion,
handleCut: canCut(delegate) ? () => handleCut(delegate) : null,
handleCut: canCut(delegate) ? () => handleCut(delegate, clipboardStatus) : null,
handleCopy: canCopy(delegate) ? () => handleCopy(delegate, clipboardStatus) : null,
handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null,
handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null,
......
......@@ -236,7 +236,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
clipboardStatus: clipboardStatus,
endpoints: endpoints,
globalEditableRegion: globalEditableRegion,
handleCut: canCut(delegate) ? () => handleCut(delegate) : null,
handleCut: canCut(delegate) ? () => handleCut(delegate, clipboardStatus) : null,
handleCopy: canCopy(delegate) ? () => handleCopy(delegate, clipboardStatus) : null,
handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null,
handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null,
......
......@@ -41,7 +41,7 @@ class _DesktopTextSelectionControls extends TextSelectionControls {
clipboardStatus: clipboardStatus,
endpoints: endpoints,
globalEditableRegion: globalEditableRegion,
handleCut: canCut(delegate) ? () => handleCut(delegate) : null,
handleCut: canCut(delegate) ? () => handleCut(delegate, clipboardStatus) : null,
handleCopy: canCopy(delegate) ? () => handleCopy(delegate, clipboardStatus) : null,
handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null,
handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null,
......
......@@ -45,7 +45,7 @@ class MaterialTextSelectionControls extends TextSelectionControls {
endpoints: endpoints,
delegate: delegate,
clipboardStatus: clipboardStatus,
handleCut: canCut(delegate) ? () => handleCut(delegate) : null,
handleCut: canCut(delegate) ? () => handleCut(delegate, clipboardStatus) : null,
handleCopy: canCopy(delegate) ? () => handleCopy(delegate, clipboardStatus) : null,
handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null,
handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null,
......
......@@ -2808,7 +2808,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
VoidCallback? _semanticsOnCut(TextSelectionControls? controls) {
return widget.selectionEnabled && cutEnabled && _hasFocus && controls?.canCut(this) == true
? () => controls!.handleCut(this)
? () => controls!.handleCut(this, _clipboardStatus)
: null;
}
......
......@@ -204,8 +204,9 @@ abstract class TextSelectionControls {
///
/// This is called by subclasses when their cut affordance is activated by
/// the user.
void handleCut(TextSelectionDelegate delegate) {
void handleCut(TextSelectionDelegate delegate, ClipboardStatusNotifier? clipboardStatus) {
delegate.cutSelection(SelectionChangedCause.toolbar);
clipboardStatus?.update();
}
/// Call [TextSelectionDelegate.copySelection] to copy current selection.
......
......@@ -8724,7 +8724,7 @@ class MockTextSelectionControls extends Fake implements TextSelectionControls {
}
@override
void handleCut(TextSelectionDelegate delegate) {
void handleCut(TextSelectionDelegate delegate, ClipboardStatusNotifier? clipboardStatus) {
cutCount += 1;
}
......
......@@ -759,6 +759,28 @@ void main() {
});
});
});
group('TextSelectionControls', () {
test('ClipboardStatusNotifier is updated on handleCut', () async {
final FakeClipboardStatusNotifier clipboardStatus = FakeClipboardStatusNotifier();
final FakeTextSelectionDelegate delegate = FakeTextSelectionDelegate();
final CustomTextSelectionControls textSelectionControls = CustomTextSelectionControls();
expect(clipboardStatus.updateCalled, false);
textSelectionControls.handleCut(delegate, clipboardStatus);
expect(clipboardStatus.updateCalled, true);
});
test('ClipboardStatusNotifier is updated on handleCopy', () async {
final FakeClipboardStatusNotifier clipboardStatus = FakeClipboardStatusNotifier();
final FakeTextSelectionDelegate delegate = FakeTextSelectionDelegate();
final CustomTextSelectionControls textSelectionControls = CustomTextSelectionControls();
expect(clipboardStatus.updateCalled, false);
textSelectionControls.handleCopy(delegate, clipboardStatus);
expect(clipboardStatus.updateCalled, true);
});
});
}
class FakeTextSelectionGestureDetectorBuilderDelegate implements TextSelectionGestureDetectorBuilderDelegate {
......@@ -872,3 +894,55 @@ class FakeRenderEditable extends RenderEditable {
selectWordCalled = true;
}
}
class CustomTextSelectionControls extends TextSelectionControls {
@override
Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textLineHeight, [VoidCallback? onTap, double? startGlyphHeight, double? endGlyphHeight]) {
throw UnimplementedError();
}
@override
Widget buildToolbar(
BuildContext context,
Rect globalEditableRegion,
double textLineHeight,
Offset position,
List<TextSelectionPoint> endpoints,
TextSelectionDelegate delegate,
ClipboardStatusNotifier clipboardStatus,
Offset? lastSecondaryTapDownPosition,
) {
throw UnimplementedError();
}
@override
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight, [double? startGlyphHeight, double? endGlyphHeight]) {
throw UnimplementedError();
}
@override
Size getHandleSize(double textLineHeight) {
throw UnimplementedError();
}
}
class FakeClipboardStatusNotifier extends ClipboardStatusNotifier {
FakeClipboardStatusNotifier() : super(value: ClipboardStatus.unknown);
@override
bool get disposed => false;
bool updateCalled = false;
@override
Future<void> update() async {
updateCalled = true;
}
}
class FakeTextSelectionDelegate extends Fake implements TextSelectionDelegate {
@override
void cutSelection(SelectionChangedCause cause) { }
@override
void copySelection(SelectionChangedCause cause) { }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment