From cf27cf8b5fb49c500fd312c989f7531a27c67797 Mon Sep 17 00:00:00 2001 From: dom Date: Sat, 18 Jul 2026 13:55:51 +0800 Subject: [PATCH] apply TextSelectionMenuFix Signed-off-by: dom --- .../flutter/text_field/editable_text.dart | 22 +++++++++++++++++-- lib/scripts/patch.ps1 | 6 ++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/common/widgets/flutter/text_field/editable_text.dart b/lib/common/widgets/flutter/text_field/editable_text.dart index 531cce324..7210079fd 100644 --- a/lib/common/widgets/flutter/text_field/editable_text.dart +++ b/lib/common/widgets/flutter/text_field/editable_text.dart @@ -4301,7 +4301,7 @@ class EditableTextState extends State return; } _showToolbarOnScreenScheduled = true; - SchedulerBinding.instance.addPostFrameCallback((Duration _) { + void scheduleToolbar(Duration _) { _showToolbarOnScreenScheduled = false; if (!mounted || _dataWhenToolbarShowScheduled == null) { return; @@ -4331,7 +4331,25 @@ class EditableTextState extends State showToolbar(); _dataWhenToolbarShowScheduled = null; } - }, debugLabel: 'EditableText.scheduleToolbar'); + } + + switch (SchedulerBinding.instance.schedulerPhase) { + case SchedulerPhase.idle: + case SchedulerPhase.postFrameCallbacks: + // During these scheduler phases we cannot guarantee + // there will be a frame after, so we use scheduleFrameCallback. + SchedulerBinding.instance.scheduleFrameCallback(scheduleToolbar); + case SchedulerPhase.transientCallbacks: + case SchedulerPhase.midFrameMicrotasks: + case SchedulerPhase.persistentCallbacks: + // During an active frame we can still schedule + // a post-frame callback to be run after the + // current frame. + SchedulerBinding.instance.addPostFrameCallback( + scheduleToolbar, + debugLabel: 'EditableText.scheduleToolbar', + ); + } } } diff --git a/lib/scripts/patch.ps1 b/lib/scripts/patch.ps1 index 990343da2..8afdfa5e3 100644 --- a/lib/scripts/patch.ps1 +++ b/lib/scripts/patch.ps1 @@ -12,6 +12,10 @@ $BottomSheetAndroidPatch = "lib/scripts/bottom_sheet_android.patch" $BottomSheetIOSFlutterPatch = "lib/scripts/bottom_sheet_ios_flutter.patch" $BottomSheetIOSPiliPlusPatch = "lib/scripts/bottom_sheet_ios_piliplus.patch" +# TODO: remove +# https://github.com/flutter/flutter/issues/185052 +$TextSelectionMenuFix = "beb2ad17004a1b118ff2bd09f55cee23198f6652"; + # https://github.com/bggRGjQaUbCoE/PiliPlus/issues/1662 $ScrollViewPatch = "lib/scripts/scroll_view.patch" @@ -66,7 +70,7 @@ if ($platform.ToLower() -eq "ios") { Set-Location $env:FLUTTER_ROOT -$picks = @() +$picks = @($TextSelectionMenuFix) $reverts = @() $patches = @($ModalBarrierPatch, $TextSelectionPatch, $MouseCursorPatch, $ImageAnimPatch, $LayoutBuilderPatch, $NavigationDrawerPatch,