reworked find in page
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:lensai/core/routing/routes.dart';
|
|||||||
import 'package:lensai/features/bangs/domain/providers/bangs.dart';
|
import 'package:lensai/features/bangs/domain/providers/bangs.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/providers/tab_state.dart';
|
import 'package:lensai/features/geckoview/domain/providers/tab_state.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/repositories/tab.dart';
|
import 'package:lensai/features/geckoview/domain/repositories/tab.dart';
|
||||||
|
import 'package:lensai/features/geckoview/features/find_in_page/presentation/controllers/find_in_page.dart';
|
||||||
import 'package:riverpod/riverpod.dart';
|
import 'package:riverpod/riverpod.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
@@ -50,6 +51,9 @@ GeckoSelectionActionService selectionActionService(Ref ref) {
|
|||||||
logger.e('No default search bang found');
|
logger.e('No default search bang found');
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
FindInPageAction((text) {
|
||||||
|
ref.read(findInPageControllerProvider.notifier).findAll(text: text);
|
||||||
|
}),
|
||||||
ShareAction((text) async {
|
ShareAction((text) async {
|
||||||
await SharePlus.instance.share(ShareParams(text: text));
|
await SharePlus.instance.share(ShareParams(text: text));
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ part of 'providers.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$selectionActionServiceHash() =>
|
String _$selectionActionServiceHash() =>
|
||||||
r'fc7344fa34f0e27772309303083804866336197b';
|
r'9393acfbc2cc0864d9e9b116e65e4c2713da2ab1';
|
||||||
|
|
||||||
/// See also [selectionActionService].
|
/// See also [selectionActionService].
|
||||||
@ProviderFor(selectionActionService)
|
@ProviderFor(selectionActionService)
|
||||||
|
|||||||
@@ -54,20 +54,6 @@ class SelectedBangData extends _$SelectedBangData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Riverpod(keepAlive: true)
|
|
||||||
class ShowFindInPage extends _$ShowFindInPage {
|
|
||||||
// ignore: document_ignores api decision
|
|
||||||
// ignore: use_setters_to_change_properties
|
|
||||||
void update(bool show) {
|
|
||||||
state = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool build() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Riverpod()
|
@Riverpod()
|
||||||
EquatableValue<List<String>> availableTabIds(
|
EquatableValue<List<String>> availableTabIds(
|
||||||
Ref ref,
|
Ref ref,
|
||||||
|
|||||||
@@ -852,21 +852,5 @@ class _SelectedBangDataProviderElement
|
|||||||
String? get domain => (origin as SelectedBangDataProvider).domain;
|
String? get domain => (origin as SelectedBangDataProvider).domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$showFindInPageHash() => r'7ee5703f7d0c7e8a8dd6b0849d7b1e0a41fe24d9';
|
|
||||||
|
|
||||||
/// See also [ShowFindInPage].
|
|
||||||
@ProviderFor(ShowFindInPage)
|
|
||||||
final showFindInPageProvider = NotifierProvider<ShowFindInPage, bool>.internal(
|
|
||||||
ShowFindInPage.new,
|
|
||||||
name: r'showFindInPageProvider',
|
|
||||||
debugGetCreateSourceHash:
|
|
||||||
const bool.fromEnvironment('dart.vm.product')
|
|
||||||
? null
|
|
||||||
: _$showFindInPageHash,
|
|
||||||
dependencies: null,
|
|
||||||
allTransitiveDependencies: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef _$ShowFindInPage = Notifier<bool>;
|
|
||||||
// ignore_for_file: type=lint
|
// ignore_for_file: type=lint
|
||||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||||
|
|||||||
+2
-4
@@ -17,7 +17,7 @@ import 'package:lensai/features/geckoview/features/browser/presentation/widgets/
|
|||||||
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/edit_url_dialog.dart';
|
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/edit_url_dialog.dart';
|
||||||
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/extension_badge_icon.dart';
|
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/extension_badge_icon.dart';
|
||||||
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/tabs_action_button.dart';
|
import 'package:lensai/features/geckoview/features/browser/presentation/widgets/tabs_action_button.dart';
|
||||||
import 'package:lensai/features/geckoview/features/find_in_page/presentation/controllers/find_in_page_visibility.dart';
|
import 'package:lensai/features/geckoview/features/find_in_page/presentation/controllers/find_in_page.dart';
|
||||||
import 'package:lensai/features/geckoview/features/readerview/presentation/widgets/reader_button.dart';
|
import 'package:lensai/features/geckoview/features/readerview/presentation/widgets/reader_button.dart';
|
||||||
import 'package:lensai/presentation/hooks/menu_controller.dart';
|
import 'package:lensai/presentation/hooks/menu_controller.dart';
|
||||||
import 'package:lensai/presentation/icons/tor_icons.dart';
|
import 'package:lensai/presentation/icons/tor_icons.dart';
|
||||||
@@ -316,9 +316,7 @@ class BrowserBottomAppBar extends HookConsumerWidget {
|
|||||||
if (selectedTabId != null)
|
if (selectedTabId != null)
|
||||||
MenuItemButton(
|
MenuItemButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ref
|
ref.read(findInPageControllerProvider.notifier).show();
|
||||||
.read(findInPageVisibilityControllerProvider.notifier)
|
|
||||||
.show();
|
|
||||||
},
|
},
|
||||||
leadingIcon: const Icon(Icons.search),
|
leadingIcon: const Icon(Icons.search),
|
||||||
child: const Text('Find in page'),
|
child: const Text('Find in page'),
|
||||||
|
|||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
||||||
|
|
||||||
part 'find_in_page.g.dart';
|
|
||||||
|
|
||||||
@Riverpod()
|
|
||||||
class FindInPageRepository extends _$FindInPageRepository {
|
|
||||||
late GeckoFindInPageService _service;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void build(String? tabId) {
|
|
||||||
_service =
|
|
||||||
(tabId != null)
|
|
||||||
? GeckoFindInPageService(tabId: tabId)
|
|
||||||
: GeckoFindInPageService.forActiveTab();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> findAll({required String text}) {
|
|
||||||
return _service.findAll(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> findNext({bool forward = true}) {
|
|
||||||
return _service.findNext(forward);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> clearMatches() {
|
|
||||||
return _service.clearMatches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-165
@@ -1,165 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'find_in_page.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// RiverpodGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
String _$findInPageRepositoryHash() =>
|
|
||||||
r'a307a7169cfc559a687483962bd595d808c159bf';
|
|
||||||
|
|
||||||
/// Copied from Dart SDK
|
|
||||||
class _SystemHash {
|
|
||||||
_SystemHash._();
|
|
||||||
|
|
||||||
static int combine(int hash, int value) {
|
|
||||||
// ignore: parameter_assignments
|
|
||||||
hash = 0x1fffffff & (hash + value);
|
|
||||||
// ignore: parameter_assignments
|
|
||||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
|
||||||
return hash ^ (hash >> 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int finish(int hash) {
|
|
||||||
// ignore: parameter_assignments
|
|
||||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
|
||||||
// ignore: parameter_assignments
|
|
||||||
hash = hash ^ (hash >> 11);
|
|
||||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _$FindInPageRepository
|
|
||||||
extends BuildlessAutoDisposeNotifier<void> {
|
|
||||||
late final String? tabId;
|
|
||||||
|
|
||||||
void build(String? tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
@ProviderFor(FindInPageRepository)
|
|
||||||
const findInPageRepositoryProvider = FindInPageRepositoryFamily();
|
|
||||||
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
class FindInPageRepositoryFamily extends Family<void> {
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
const FindInPageRepositoryFamily();
|
|
||||||
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
FindInPageRepositoryProvider call(String? tabId) {
|
|
||||||
return FindInPageRepositoryProvider(tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
FindInPageRepositoryProvider getProviderOverride(
|
|
||||||
covariant FindInPageRepositoryProvider provider,
|
|
||||||
) {
|
|
||||||
return call(provider.tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
|
||||||
|
|
||||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
|
||||||
_allTransitiveDependencies;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String? get name => r'findInPageRepositoryProvider';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
class FindInPageRepositoryProvider
|
|
||||||
extends AutoDisposeNotifierProviderImpl<FindInPageRepository, void> {
|
|
||||||
/// See also [FindInPageRepository].
|
|
||||||
FindInPageRepositoryProvider(String? tabId)
|
|
||||||
: this._internal(
|
|
||||||
() => FindInPageRepository()..tabId = tabId,
|
|
||||||
from: findInPageRepositoryProvider,
|
|
||||||
name: r'findInPageRepositoryProvider',
|
|
||||||
debugGetCreateSourceHash:
|
|
||||||
const bool.fromEnvironment('dart.vm.product')
|
|
||||||
? null
|
|
||||||
: _$findInPageRepositoryHash,
|
|
||||||
dependencies: FindInPageRepositoryFamily._dependencies,
|
|
||||||
allTransitiveDependencies:
|
|
||||||
FindInPageRepositoryFamily._allTransitiveDependencies,
|
|
||||||
tabId: tabId,
|
|
||||||
);
|
|
||||||
|
|
||||||
FindInPageRepositoryProvider._internal(
|
|
||||||
super._createNotifier, {
|
|
||||||
required super.name,
|
|
||||||
required super.dependencies,
|
|
||||||
required super.allTransitiveDependencies,
|
|
||||||
required super.debugGetCreateSourceHash,
|
|
||||||
required super.from,
|
|
||||||
required this.tabId,
|
|
||||||
}) : super.internal();
|
|
||||||
|
|
||||||
final String? tabId;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void runNotifierBuild(covariant FindInPageRepository notifier) {
|
|
||||||
return notifier.build(tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Override overrideWith(FindInPageRepository Function() create) {
|
|
||||||
return ProviderOverride(
|
|
||||||
origin: this,
|
|
||||||
override: FindInPageRepositoryProvider._internal(
|
|
||||||
() => create()..tabId = tabId,
|
|
||||||
from: from,
|
|
||||||
name: null,
|
|
||||||
dependencies: null,
|
|
||||||
allTransitiveDependencies: null,
|
|
||||||
debugGetCreateSourceHash: null,
|
|
||||||
tabId: tabId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
AutoDisposeNotifierProviderElement<FindInPageRepository, void>
|
|
||||||
createElement() {
|
|
||||||
return _FindInPageRepositoryProviderElement(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return other is FindInPageRepositoryProvider && other.tabId == tabId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
|
||||||
hash = _SystemHash.combine(hash, tabId.hashCode);
|
|
||||||
|
|
||||||
return _SystemHash.finish(hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
|
||||||
// ignore: unused_element
|
|
||||||
mixin FindInPageRepositoryRef on AutoDisposeNotifierProviderRef<void> {
|
|
||||||
/// The parameter `tabId` of this provider.
|
|
||||||
String? get tabId;
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FindInPageRepositoryProviderElement
|
|
||||||
extends AutoDisposeNotifierProviderElement<FindInPageRepository, void>
|
|
||||||
with FindInPageRepositoryRef {
|
|
||||||
_FindInPageRepositoryProviderElement(super.provider);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String? get tabId => (origin as FindInPageRepositoryProvider).tabId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore_for_file: type=lint
|
|
||||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||||
|
import 'package:lensai/extensions/nullable.dart';
|
||||||
|
import 'package:lensai/features/geckoview/domain/providers/selected_tab.dart';
|
||||||
|
import 'package:lensai/features/geckoview/domain/providers/tab_state.dart';
|
||||||
|
import 'package:lensai/features/geckoview/features/find_in_page/presentation/domain/entities/find_in_page_state.dart';
|
||||||
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
|
||||||
|
part 'find_in_page.g.dart';
|
||||||
|
|
||||||
|
@Riverpod()
|
||||||
|
class FindInPageController extends _$FindInPageController {
|
||||||
|
void show() {
|
||||||
|
state = state.copyWith.visible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hide() {
|
||||||
|
state = FindInPageState.hidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> findAll({required String text}) {
|
||||||
|
final service = GeckoFindInPageService(
|
||||||
|
tabId: ref.read(selectedTabProvider),
|
||||||
|
);
|
||||||
|
|
||||||
|
state = FindInPageState(visible: true, searchText: text);
|
||||||
|
|
||||||
|
return service.findAll(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> findNext({bool forward = true}) {
|
||||||
|
final service = GeckoFindInPageService(
|
||||||
|
tabId: ref.read(selectedTabProvider),
|
||||||
|
);
|
||||||
|
|
||||||
|
state = state.copyWith.visible(true);
|
||||||
|
|
||||||
|
return service.findNext(forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> clearMatches() {
|
||||||
|
final service = GeckoFindInPageService(
|
||||||
|
tabId: ref.read(selectedTabProvider),
|
||||||
|
);
|
||||||
|
|
||||||
|
return service.clearMatches();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
FindInPageState build() {
|
||||||
|
ref.listen(selectedTabStateProvider, (previous, next) async {
|
||||||
|
if (state.visible && state.searchText.isNotEmpty) {
|
||||||
|
if (previous != null) {
|
||||||
|
final loadingOrReloading =
|
||||||
|
previous.isLoading == true && next?.isLoading == false;
|
||||||
|
final tabSwitch = previous.id != next?.id;
|
||||||
|
|
||||||
|
if (loadingOrReloading || tabSwitch) {
|
||||||
|
await clearMatches();
|
||||||
|
await findAll(text: state.searchText!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return FindInPageState.hidden();
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-11
@@ -1,28 +1,28 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
part of 'find_in_page_visibility.dart';
|
part of 'find_in_page.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// RiverpodGenerator
|
// RiverpodGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$findInPageVisibilityControllerHash() =>
|
String _$findInPageControllerHash() =>
|
||||||
r'365819c6b181ff2cefc022360413a918457e06d7';
|
r'bb8584767aa8ad93e3bccd69d1012daaa8c5e9ea';
|
||||||
|
|
||||||
/// See also [FindInPageVisibilityController].
|
/// See also [FindInPageController].
|
||||||
@ProviderFor(FindInPageVisibilityController)
|
@ProviderFor(FindInPageController)
|
||||||
final findInPageVisibilityControllerProvider =
|
final findInPageControllerProvider =
|
||||||
AutoDisposeNotifierProvider<FindInPageVisibilityController, bool>.internal(
|
AutoDisposeNotifierProvider<FindInPageController, FindInPageState>.internal(
|
||||||
FindInPageVisibilityController.new,
|
FindInPageController.new,
|
||||||
name: r'findInPageVisibilityControllerProvider',
|
name: r'findInPageControllerProvider',
|
||||||
debugGetCreateSourceHash:
|
debugGetCreateSourceHash:
|
||||||
const bool.fromEnvironment('dart.vm.product')
|
const bool.fromEnvironment('dart.vm.product')
|
||||||
? null
|
? null
|
||||||
: _$findInPageVisibilityControllerHash,
|
: _$findInPageControllerHash,
|
||||||
dependencies: null,
|
dependencies: null,
|
||||||
allTransitiveDependencies: null,
|
allTransitiveDependencies: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef _$FindInPageVisibilityController = AutoDisposeNotifier<bool>;
|
typedef _$FindInPageController = AutoDisposeNotifier<FindInPageState>;
|
||||||
// ignore_for_file: type=lint
|
// ignore_for_file: type=lint
|
||||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
||||||
|
|
||||||
part 'find_in_page_visibility.g.dart';
|
|
||||||
|
|
||||||
@Riverpod()
|
|
||||||
class FindInPageVisibilityController extends _$FindInPageVisibilityController {
|
|
||||||
void show() {
|
|
||||||
state = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hide() {
|
|
||||||
state = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool build() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
|
|
||||||
|
part 'find_in_page_state.g.dart';
|
||||||
|
|
||||||
|
@CopyWith()
|
||||||
|
class FindInPageState with FastEquatable {
|
||||||
|
final bool visible;
|
||||||
|
final String? searchText;
|
||||||
|
|
||||||
|
FindInPageState({required this.visible, required this.searchText});
|
||||||
|
|
||||||
|
FindInPageState.hidden() : visible = false, searchText = null;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get hashParameters => [visible, searchText];
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'find_in_page_state.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// CopyWithGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
abstract class _$FindInPageStateCWProxy {
|
||||||
|
FindInPageState visible(bool visible);
|
||||||
|
|
||||||
|
FindInPageState searchText(String? searchText);
|
||||||
|
|
||||||
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FindInPageState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
|
///
|
||||||
|
/// Usage
|
||||||
|
/// ```dart
|
||||||
|
/// FindInPageState(...).copyWith(id: 12, name: "My name")
|
||||||
|
/// ````
|
||||||
|
FindInPageState call({bool visible, String? searchText});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFindInPageState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFindInPageState.copyWith.fieldName(...)`
|
||||||
|
class _$FindInPageStateCWProxyImpl implements _$FindInPageStateCWProxy {
|
||||||
|
const _$FindInPageStateCWProxyImpl(this._value);
|
||||||
|
|
||||||
|
final FindInPageState _value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
FindInPageState visible(bool visible) => this(visible: visible);
|
||||||
|
|
||||||
|
@override
|
||||||
|
FindInPageState searchText(String? searchText) =>
|
||||||
|
this(searchText: searchText);
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FindInPageState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
|
///
|
||||||
|
/// Usage
|
||||||
|
/// ```dart
|
||||||
|
/// FindInPageState(...).copyWith(id: 12, name: "My name")
|
||||||
|
/// ````
|
||||||
|
FindInPageState call({
|
||||||
|
Object? visible = const $CopyWithPlaceholder(),
|
||||||
|
Object? searchText = const $CopyWithPlaceholder(),
|
||||||
|
}) {
|
||||||
|
return FindInPageState(
|
||||||
|
visible:
|
||||||
|
visible == const $CopyWithPlaceholder()
|
||||||
|
? _value.visible
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: visible as bool,
|
||||||
|
searchText:
|
||||||
|
searchText == const $CopyWithPlaceholder()
|
||||||
|
? _value.searchText
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: searchText as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension $FindInPageStateCopyWith on FindInPageState {
|
||||||
|
/// Returns a callable class that can be used as follows: `instanceOfFindInPageState.copyWith(...)` or like so:`instanceOfFindInPageState.copyWith.fieldName(...)`.
|
||||||
|
// ignore: library_private_types_in_public_api
|
||||||
|
_$FindInPageStateCWProxy get copyWith => _$FindInPageStateCWProxyImpl(this);
|
||||||
|
}
|
||||||
+23
-16
@@ -2,8 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/providers/tab_state.dart';
|
import 'package:lensai/features/geckoview/domain/providers/tab_state.dart';
|
||||||
import 'package:lensai/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
|
import 'package:lensai/features/geckoview/features/find_in_page/presentation/controllers/find_in_page.dart';
|
||||||
import 'package:lensai/features/geckoview/features/find_in_page/presentation/controllers/find_in_page_visibility.dart';
|
|
||||||
|
|
||||||
class FindInPageWidget extends HookConsumerWidget {
|
class FindInPageWidget extends HookConsumerWidget {
|
||||||
final EdgeInsetsGeometry padding;
|
final EdgeInsetsGeometry padding;
|
||||||
@@ -12,15 +11,15 @@ class FindInPageWidget extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final showFindInPage = ref.watch(findInPageVisibilityControllerProvider);
|
final findInPageState = ref.watch(findInPageControllerProvider);
|
||||||
final findInteractionController = ref.watch(
|
|
||||||
findInPageRepositoryProvider(null).notifier,
|
final textController = useTextEditingController(
|
||||||
|
text: findInPageState.searchText,
|
||||||
|
keys: [findInPageState.searchText],
|
||||||
);
|
);
|
||||||
|
|
||||||
final textController = useTextEditingController();
|
|
||||||
|
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: showFindInPage,
|
visible: findInPageState.visible,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: padding,
|
padding: padding,
|
||||||
child: Material(
|
child: Material(
|
||||||
@@ -38,9 +37,13 @@ class FindInPageWidget extends HookConsumerWidget {
|
|||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
onSubmitted: (value) async {
|
onSubmitted: (value) async {
|
||||||
if (value == '') {
|
if (value == '') {
|
||||||
await findInteractionController.clearMatches();
|
await ref
|
||||||
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.clearMatches();
|
||||||
} else {
|
} else {
|
||||||
await findInteractionController.findAll(text: value);
|
await ref
|
||||||
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.findAll(text: value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -69,23 +72,27 @@ class FindInPageWidget extends HookConsumerWidget {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.arrow_upward),
|
icon: const Icon(Icons.arrow_upward),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await findInteractionController.findNext(forward: false);
|
await ref
|
||||||
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.findNext(forward: false);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.arrow_downward),
|
icon: const Icon(Icons.arrow_downward),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await findInteractionController.findNext();
|
await ref
|
||||||
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.findNext();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.clear),
|
icon: const Icon(Icons.clear),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
ref
|
ref.read(findInPageControllerProvider.notifier).hide();
|
||||||
.read(findInPageVisibilityControllerProvider.notifier)
|
|
||||||
.hide();
|
|
||||||
|
|
||||||
await findInteractionController.clearMatches();
|
await ref
|
||||||
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.clearMatches();
|
||||||
textController.clear();
|
textController.clear();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
+9
@@ -60,6 +60,15 @@ class PrivateSearchAction extends BaseSelectionAction {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FindInPageAction extends BaseSelectionAction {
|
||||||
|
FindInPageAction(PerformAction action)
|
||||||
|
: super(
|
||||||
|
id: 'CUSTOM_CONTEXT_MENU_FIND_IN_PAGE',
|
||||||
|
title: 'Find in page',
|
||||||
|
performAction: action,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class ShareAction extends BaseSelectionAction {
|
class ShareAction extends BaseSelectionAction {
|
||||||
ShareAction(PerformAction action)
|
ShareAction(PerformAction action)
|
||||||
: super(
|
: super(
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ class GeckoFindInPageService {
|
|||||||
GeckoFindInPageService({required this.tabId, GeckoFindApi? api})
|
GeckoFindInPageService({required this.tabId, GeckoFindApi? api})
|
||||||
: _api = api ?? _apiInstance;
|
: _api = api ?? _apiInstance;
|
||||||
|
|
||||||
GeckoFindInPageService.forActiveTab({GeckoFindApi? api})
|
|
||||||
: _api = api ?? _apiInstance,
|
|
||||||
tabId = null;
|
|
||||||
|
|
||||||
Future<void> findAll(String text) {
|
Future<void> findAll(String text) {
|
||||||
return _api.findAll(tabId, text);
|
return _api.findAll(tabId, text);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user