Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix OCR selection control reachability

laurenspriem0e9b626aaa2b
diff --git a/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart b/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart
index f74d58867c..311769eb84 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/inline_text_detection.dart
@@ -653,29 +653,29 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {
final Size viewportSize = constraints.biggest;
return _OcrGestureHitTestBox(
hitTest: (localPosition, globalPosition) {
- if (textRegionsOnly &&
- _detectorController.isPointOnInteractiveSelectionUi(
- globalPosition,
- )) {
- return true;
- }
final zoomTransform = InheritedDetailPageState.of(
context,
).zoomTransformNotifier.value;
- if (!_isLocalPointEligibleForOcrGesture(
- localPosition,
- viewportSize,
- zoomTransform,
- )) {
- return false;
- }
- return !textRegionsOnly ||
- _detectorController.isPointOnSelectableText(globalPosition) ||
- _isLocalPointInDetectedTextRegion(
- localPosition,
- viewportSize,
- zoomTransform,
- );
+ return shouldCaptureOcrGesture(
+ pointOnInteractiveSelectionUi: _detectorController
+ .isPointOnInteractiveSelectionUi(globalPosition),
+ pointEligibleForOcr: _isLocalPointEligibleForOcrGesture(
+ localPosition,
+ viewportSize,
+ zoomTransform,
+ ),
+ textRegionsOnly: textRegionsOnly,
+ pointOnSelectableText:
+ textRegionsOnly &&
+ _detectorController.isPointOnSelectableText(globalPosition),
+ pointInDetectedTextRegion:
+ textRegionsOnly &&
+ _isLocalPointInDetectedTextRegion(
+ localPosition,
+ viewportSize,
+ zoomTransform,
+ ),
+ );
},
child: child,
);
diff --git a/mobile/apps/photos/lib/ui/viewer/file/ocr/text_region_hit_test.dart b/mobile/apps/photos/lib/ui/viewer/file/ocr/text_region_hit_test.dart
index f346f829e8..e068029bc6 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/ocr/text_region_hit_test.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/ocr/text_region_hit_test.dart
@@ -1,6 +1,18 @@
import "package:flutter/widgets.dart";
import "package:mobile_ocr/models/text_region.dart";
+bool shouldCaptureOcrGesture({
+ required bool pointOnInteractiveSelectionUi,
+ required bool pointEligibleForOcr,
+ required bool textRegionsOnly,
+ required bool pointOnSelectableText,
+ required bool pointInDetectedTextRegion,
+}) {
+ if (pointOnInteractiveSelectionUi) return true;
+ if (!pointEligibleForOcr) return false;
+ return !textRegionsOnly || pointOnSelectableText || pointInDetectedTextRegion;
+}
+
Offset viewportPointBeforeZoom({
required Offset point,
required Size viewportSize,
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 892b3cc917..4d1562eedf 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -165,8 +165,8 @@ dependencies:
ml_linalg: 13.12.6
mobile_ocr:
git:
- url: https://github.com/ente/mobile_ocr
- ref: 37aee4c4ff77c59a4ab46e272e31a53a035f628e
+ url: https://github.com/laurens-pilot/mobile_ocr
+ ref: 09fc9b7e9366e568de0047a369ac4c852529f748
modal_bottom_sheet: 3.0.0
motionphoto:
git:
diff --git a/mobile/apps/photos/test/ui/viewer/file/ocr/text_region_hit_test_test.dart b/mobile/apps/photos/test/ui/viewer/file/ocr/text_region_hit_test_test.dart
index 2900683e3b..aed75f82fa 100644
--- a/mobile/apps/photos/test/ui/viewer/file/ocr/text_region_hit_test_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/file/ocr/text_region_hit_test_test.dart
@@ -53,6 +53,32 @@ void main() {
);
});
+ test("keeps interactive selection controls tappable outside the image", () {
+ expect(
+ shouldCaptureOcrGesture(
+ pointOnInteractiveSelectionUi: true,
+ pointEligibleForOcr: false,
+ textRegionsOnly: false,
+ pointOnSelectableText: false,
+ pointInDetectedTextRegion: false,
+ ),
+ isTrue,
+ );
+ });
+
+ test("does not capture non-interactive points outside the image", () {
+ expect(
+ shouldCaptureOcrGesture(
+ pointOnInteractiveSelectionUi: false,
+ pointEligibleForOcr: false,
+ textRegionsOnly: false,
+ pointOnSelectableText: false,
+ pointInDetectedTextRegion: false,
+ ),
+ isFalse,
+ );
+ });
+
test("applies hit slop in viewport pixels", () {
expect(
isViewportPointInTextRegions(
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index 6d593fc708..0c47768e39 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -1774,9 +1774,9 @@ packages:
dependency: transitive
description:
path: "."
- ref: "37aee4c4ff77c59a4ab46e272e31a53a035f628e"
- resolved-ref: "37aee4c4ff77c59a4ab46e272e31a53a035f628e"
- url: "https://github.com/ente/mobile_ocr"
+ ref: "09fc9b7e9366e568de0047a369ac4c852529f748"
+ resolved-ref: "09fc9b7e9366e568de0047a369ac4c852529f748"
+ url: "https://github.com/laurens-pilot/mobile_ocr"
source: git
version: "1.0.0"
mockito: