improve find in page
This commit is contained in:
@@ -1,17 +1,23 @@
|
|||||||
import 'package:fast_equatable/fast_equatable.dart';
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
|
|
||||||
class FindResultState with FastEquatable {
|
class FindResultState with FastEquatable {
|
||||||
|
final String? lastSearchText;
|
||||||
|
|
||||||
final int activeMatchOrdinal;
|
final int activeMatchOrdinal;
|
||||||
final int numberOfMatches;
|
final int numberOfMatches;
|
||||||
final bool isDoneCounting;
|
final bool isDoneCounting;
|
||||||
|
|
||||||
|
bool get hasMatches => numberOfMatches > 0;
|
||||||
|
|
||||||
FindResultState({
|
FindResultState({
|
||||||
|
required this.lastSearchText,
|
||||||
required this.activeMatchOrdinal,
|
required this.activeMatchOrdinal,
|
||||||
required this.numberOfMatches,
|
required this.numberOfMatches,
|
||||||
required this.isDoneCounting,
|
required this.isDoneCounting,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory FindResultState.$default() => FindResultState(
|
factory FindResultState.$default() => FindResultState(
|
||||||
|
lastSearchText: null,
|
||||||
activeMatchOrdinal: -1,
|
activeMatchOrdinal: -1,
|
||||||
numberOfMatches: 0,
|
numberOfMatches: 0,
|
||||||
isDoneCounting: false,
|
isDoneCounting: false,
|
||||||
@@ -19,6 +25,7 @@ class FindResultState with FastEquatable {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get hashParameters => [
|
List<Object?> get hashParameters => [
|
||||||
|
lastSearchText,
|
||||||
activeMatchOrdinal,
|
activeMatchOrdinal,
|
||||||
numberOfMatches,
|
numberOfMatches,
|
||||||
isDoneCounting,
|
isDoneCounting,
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import 'package:lensai/features/geckoview/domain/entities/states/security.dart';
|
|||||||
import 'package:lensai/features/geckoview/domain/entities/states/tab.dart';
|
import 'package:lensai/features/geckoview/domain/entities/states/tab.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/providers.dart';
|
import 'package:lensai/features/geckoview/domain/providers.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/providers/selected_tab.dart';
|
import 'package:lensai/features/geckoview/domain/providers/selected_tab.dart';
|
||||||
|
import 'package:lensai/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
|
||||||
import 'package:lensai/features/geckoview/utils/image_helper.dart';
|
import 'package:lensai/features/geckoview/utils/image_helper.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:rxdart/rxdart.dart';
|
||||||
|
|
||||||
part 'tab_state.g.dart';
|
part 'tab_state.g.dart';
|
||||||
|
|
||||||
@@ -105,19 +107,24 @@ class TabStates extends _$TabStates {
|
|||||||
|
|
||||||
void _onFindResultsChange(FindResultsEvent event) {
|
void _onFindResultsChange(FindResultsEvent event) {
|
||||||
final FindResultsEvent(:tabId, :results) = event;
|
final FindResultsEvent(:tabId, :results) = event;
|
||||||
|
final current = state[tabId] ?? TabState.$default(tabId);
|
||||||
|
|
||||||
if (results.isNotEmpty) {
|
if (results.isNotEmpty) {
|
||||||
final result = results.last;
|
final result = results.last;
|
||||||
|
|
||||||
final current = state[tabId] ?? TabState.$default(tabId);
|
|
||||||
state = {...state}
|
state = {...state}
|
||||||
..[tabId] = current.copyWith.findResultState(
|
..[tabId] = current.copyWith.findResultState(
|
||||||
FindResultState(
|
FindResultState(
|
||||||
|
lastSearchText: ref.read(findInPageRepositoryProvider(tabId)),
|
||||||
activeMatchOrdinal: result.activeMatchOrdinal,
|
activeMatchOrdinal: result.activeMatchOrdinal,
|
||||||
numberOfMatches: result.numberOfMatches,
|
numberOfMatches: result.numberOfMatches,
|
||||||
isDoneCounting: result.isDoneCounting,
|
isDoneCounting: result.isDoneCounting,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else if (current.findResultState.hasMatches) {
|
||||||
|
state = {
|
||||||
|
...state,
|
||||||
|
}..[tabId] = current.copyWith.findResultState(FindResultState.$default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,9 +151,11 @@ class TabStates extends _$TabStates {
|
|||||||
eventService.readerableEvents.listen((event) {
|
eventService.readerableEvents.listen((event) {
|
||||||
_onReaderableStateChange(event);
|
_onReaderableStateChange(event);
|
||||||
}),
|
}),
|
||||||
eventService.findResultsEvent.listen((event) {
|
eventService.findResultsEvent
|
||||||
_onFindResultsChange(event);
|
.debounceTime(const Duration(milliseconds: 25))
|
||||||
}),
|
.listen((event) {
|
||||||
|
_onFindResultsChange(event);
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
ref.listen(fireImmediately: true, engineReadyStateProvider, (
|
ref.listen(fireImmediately: true, engineReadyStateProvider, (
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ final selectedTabStateProvider = AutoDisposeProvider<TabState?>.internal(
|
|||||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||||
// ignore: unused_element
|
// ignore: unused_element
|
||||||
typedef SelectedTabStateRef = AutoDisposeProviderRef<TabState?>;
|
typedef SelectedTabStateRef = AutoDisposeProviderRef<TabState?>;
|
||||||
String _$tabStatesHash() => r'3a906aec8c4e650de8d5d2461ff45a99b8a0a3b9';
|
String _$tabStatesHash() => r'f0b7b4fbfab633695b3e7e7457a6f84bc6e81b88';
|
||||||
|
|
||||||
/// See also [TabStates].
|
/// See also [TabStates].
|
||||||
@ProviderFor(TabStates)
|
@ProviderFor(TabStates)
|
||||||
|
|||||||
+4
-4
@@ -6,12 +6,12 @@ part 'find_in_page_state.g.dart';
|
|||||||
@CopyWith()
|
@CopyWith()
|
||||||
class FindInPageState with FastEquatable {
|
class FindInPageState with FastEquatable {
|
||||||
final bool visible;
|
final bool visible;
|
||||||
final String? searchText;
|
final String? lastSearchText;
|
||||||
|
|
||||||
FindInPageState({required this.visible, required this.searchText});
|
FindInPageState({required this.visible, required this.lastSearchText});
|
||||||
|
|
||||||
FindInPageState.hidden() : visible = false, searchText = null;
|
FindInPageState.hidden() : visible = false, lastSearchText = null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get hashParameters => [visible, searchText];
|
List<Object?> get hashParameters => [visible, lastSearchText];
|
||||||
}
|
}
|
||||||
+9
-9
@@ -9,7 +9,7 @@ part of 'find_in_page_state.dart';
|
|||||||
abstract class _$FindInPageStateCWProxy {
|
abstract class _$FindInPageStateCWProxy {
|
||||||
FindInPageState visible(bool visible);
|
FindInPageState visible(bool visible);
|
||||||
|
|
||||||
FindInPageState searchText(String? searchText);
|
FindInPageState lastSearchText(String? lastSearchText);
|
||||||
|
|
||||||
/// 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.
|
/// 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.
|
||||||
///
|
///
|
||||||
@@ -17,7 +17,7 @@ abstract class _$FindInPageStateCWProxy {
|
|||||||
/// ```dart
|
/// ```dart
|
||||||
/// FindInPageState(...).copyWith(id: 12, name: "My name")
|
/// FindInPageState(...).copyWith(id: 12, name: "My name")
|
||||||
/// ````
|
/// ````
|
||||||
FindInPageState call({bool visible, String? searchText});
|
FindInPageState call({bool visible, String? lastSearchText});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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(...)`
|
/// 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(...)`
|
||||||
@@ -30,8 +30,8 @@ class _$FindInPageStateCWProxyImpl implements _$FindInPageStateCWProxy {
|
|||||||
FindInPageState visible(bool visible) => this(visible: visible);
|
FindInPageState visible(bool visible) => this(visible: visible);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FindInPageState searchText(String? searchText) =>
|
FindInPageState lastSearchText(String? lastSearchText) =>
|
||||||
this(searchText: searchText);
|
this(lastSearchText: lastSearchText);
|
||||||
|
|
||||||
@override
|
@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.
|
/// 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.
|
||||||
@@ -42,7 +42,7 @@ class _$FindInPageStateCWProxyImpl implements _$FindInPageStateCWProxy {
|
|||||||
/// ````
|
/// ````
|
||||||
FindInPageState call({
|
FindInPageState call({
|
||||||
Object? visible = const $CopyWithPlaceholder(),
|
Object? visible = const $CopyWithPlaceholder(),
|
||||||
Object? searchText = const $CopyWithPlaceholder(),
|
Object? lastSearchText = const $CopyWithPlaceholder(),
|
||||||
}) {
|
}) {
|
||||||
return FindInPageState(
|
return FindInPageState(
|
||||||
visible:
|
visible:
|
||||||
@@ -50,11 +50,11 @@ class _$FindInPageStateCWProxyImpl implements _$FindInPageStateCWProxy {
|
|||||||
? _value.visible
|
? _value.visible
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: visible as bool,
|
: visible as bool,
|
||||||
searchText:
|
lastSearchText:
|
||||||
searchText == const $CopyWithPlaceholder()
|
lastSearchText == const $CopyWithPlaceholder()
|
||||||
? _value.searchText
|
? _value.lastSearchText
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: searchText as String?,
|
: lastSearchText as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||||
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
|
||||||
|
part 'find_in_page.g.dart';
|
||||||
|
|
||||||
|
@Riverpod(keepAlive: true)
|
||||||
|
class FindInPageRepository extends _$FindInPageRepository
|
||||||
|
implements GeckoFindInPageService {
|
||||||
|
@override
|
||||||
|
String? build(String? tabId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> clearMatches() {
|
||||||
|
final service = GeckoFindInPageService(tabId: tabId);
|
||||||
|
|
||||||
|
state = null;
|
||||||
|
|
||||||
|
return service.clearMatches();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> findAll(String text) {
|
||||||
|
final service = GeckoFindInPageService(tabId: tabId);
|
||||||
|
|
||||||
|
state = text;
|
||||||
|
|
||||||
|
return service.findAll(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> findNext(bool forward) {
|
||||||
|
final service = GeckoFindInPageService(tabId: tabId);
|
||||||
|
return service.findNext(forward);
|
||||||
|
}
|
||||||
|
}
|
||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'find_in_page.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// RiverpodGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
String _$findInPageRepositoryHash() =>
|
||||||
|
r'c289f136c27a22978f15668a13d7044eb39c3355';
|
||||||
|
|
||||||
|
/// 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 BuildlessNotifier<String?> {
|
||||||
|
late final String? tabId;
|
||||||
|
|
||||||
|
String? build(String? tabId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// See also [FindInPageRepository].
|
||||||
|
@ProviderFor(FindInPageRepository)
|
||||||
|
const findInPageRepositoryProvider = FindInPageRepositoryFamily();
|
||||||
|
|
||||||
|
/// See also [FindInPageRepository].
|
||||||
|
class FindInPageRepositoryFamily extends Family<String?> {
|
||||||
|
/// 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 NotifierProviderImpl<FindInPageRepository, String?> {
|
||||||
|
/// 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
|
||||||
|
String? 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
|
||||||
|
NotifierProviderElement<FindInPageRepository, String?> 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 NotifierProviderRef<String?> {
|
||||||
|
/// The parameter `tabId` of this provider.
|
||||||
|
String? get tabId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FindInPageRepositoryProviderElement
|
||||||
|
extends NotifierProviderElement<FindInPageRepository, String?>
|
||||||
|
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
|
||||||
+18
-20
@@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
|
||||||
import 'package:lensai/extensions/nullable.dart';
|
import 'package:lensai/extensions/nullable.dart';
|
||||||
import 'package:lensai/features/geckoview/domain/providers/selected_tab.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/domain/providers/tab_state.dart';
|
||||||
import 'package:lensai/features/geckoview/features/find_in_page/presentation/domain/entities/find_in_page_state.dart';
|
import 'package:lensai/features/geckoview/features/find_in_page/domain/entities/find_in_page_state.dart';
|
||||||
|
import 'package:lensai/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
|
||||||
part 'find_in_page.g.dart';
|
part 'find_in_page.g.dart';
|
||||||
@@ -13,24 +13,23 @@ class FindInPageController extends _$FindInPageController {
|
|||||||
state = state.copyWith.visible(true);
|
state = state.copyWith.visible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide() {
|
Future<void> hide() async {
|
||||||
|
await clearMatches();
|
||||||
state = FindInPageState.hidden();
|
state = FindInPageState.hidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> findAll({required String text}) {
|
Future<void> findAll({required String text}) {
|
||||||
final service = GeckoFindInPageService(
|
final tabId = ref.read(selectedTabProvider);
|
||||||
tabId: ref.read(selectedTabProvider),
|
final service = ref.read(findInPageRepositoryProvider(tabId).notifier);
|
||||||
);
|
|
||||||
|
|
||||||
state = FindInPageState(visible: true, searchText: text);
|
state = FindInPageState(visible: true, lastSearchText: text);
|
||||||
|
|
||||||
return service.findAll(text);
|
return service.findAll(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> findNext({bool forward = true}) {
|
Future<void> findNext({bool forward = true}) {
|
||||||
final service = GeckoFindInPageService(
|
final tabId = ref.read(selectedTabProvider);
|
||||||
tabId: ref.read(selectedTabProvider),
|
final service = ref.read(findInPageRepositoryProvider(tabId).notifier);
|
||||||
);
|
|
||||||
|
|
||||||
state = state.copyWith.visible(true);
|
state = state.copyWith.visible(true);
|
||||||
|
|
||||||
@@ -38,9 +37,8 @@ class FindInPageController extends _$FindInPageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> clearMatches() {
|
Future<void> clearMatches() {
|
||||||
final service = GeckoFindInPageService(
|
final tabId = ref.read(selectedTabProvider);
|
||||||
tabId: ref.read(selectedTabProvider),
|
final service = ref.read(findInPageRepositoryProvider(tabId).notifier);
|
||||||
);
|
|
||||||
|
|
||||||
return service.clearMatches();
|
return service.clearMatches();
|
||||||
}
|
}
|
||||||
@@ -48,15 +46,15 @@ class FindInPageController extends _$FindInPageController {
|
|||||||
@override
|
@override
|
||||||
FindInPageState build() {
|
FindInPageState build() {
|
||||||
ref.listen(selectedTabStateProvider, (previous, next) async {
|
ref.listen(selectedTabStateProvider, (previous, next) async {
|
||||||
if (state.visible && state.searchText.isNotEmpty) {
|
if (state.visible && state.lastSearchText.isNotEmpty) {
|
||||||
if (previous != null) {
|
if (previous != null && next != null) {
|
||||||
final loadingOrReloading =
|
final loadingOrReloading =
|
||||||
previous.isLoading == true && next?.isLoading == false;
|
previous.isLoading == true && next.isLoading == false;
|
||||||
final tabSwitch = previous.id != next?.id;
|
final tabSwitchWithoutResults =
|
||||||
|
previous.id != next.id && !next.findResultState.hasMatches;
|
||||||
|
|
||||||
if (loadingOrReloading || tabSwitch) {
|
if (loadingOrReloading || tabSwitchWithoutResults) {
|
||||||
await clearMatches();
|
await findAll(text: state.lastSearchText!);
|
||||||
await findAll(text: state.searchText!);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ part of 'find_in_page.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$findInPageControllerHash() =>
|
String _$findInPageControllerHash() =>
|
||||||
r'bb8584767aa8ad93e3bccd69d1012daaa8c5e9ea';
|
r'b75a1edb4c25246bf2a5f5c9a807d6151b23856e';
|
||||||
|
|
||||||
/// See also [FindInPageController].
|
/// See also [FindInPageController].
|
||||||
@ProviderFor(FindInPageController)
|
@ProviderFor(FindInPageController)
|
||||||
|
|||||||
+21
-34
@@ -12,14 +12,17 @@ class FindInPageWidget extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final findInPageState = ref.watch(findInPageControllerProvider);
|
final findInPageState = ref.watch(findInPageControllerProvider);
|
||||||
|
final searchResult = ref.watch(
|
||||||
|
selectedTabStateProvider.select((state) => state?.findResultState),
|
||||||
|
);
|
||||||
|
|
||||||
final textController = useTextEditingController(
|
final textController = useTextEditingController(
|
||||||
text: findInPageState.searchText,
|
text: searchResult?.lastSearchText ?? findInPageState.lastSearchText,
|
||||||
keys: [findInPageState.searchText],
|
keys: [searchResult?.lastSearchText, findInPageState.lastSearchText],
|
||||||
);
|
);
|
||||||
|
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: findInPageState.visible,
|
visible: findInPageState.visible || searchResult?.hasMatches == true,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: padding,
|
padding: padding,
|
||||||
child: Material(
|
child: Material(
|
||||||
@@ -48,51 +51,35 @@ class FindInPageWidget extends HookConsumerWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
HookConsumer(
|
Text(
|
||||||
builder: (context, ref, child) {
|
(searchResult != null && searchResult.hasMatches)
|
||||||
final searchResult = ref.watch(
|
? '${searchResult.activeMatchOrdinal + 1} of ${searchResult.numberOfMatches}'
|
||||||
selectedTabStateProvider.select(
|
: 'Not found',
|
||||||
(state) => state?.findResultState,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (searchResult != null) {
|
|
||||||
if (searchResult.numberOfMatches == 0) {
|
|
||||||
return const Text('Not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Text(
|
|
||||||
'${searchResult.activeMatchOrdinal + 1} of ${searchResult.numberOfMatches}',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.arrow_upward),
|
icon: const Icon(Icons.arrow_upward),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref
|
if (searchResult?.hasMatches ?? false) {
|
||||||
.read(findInPageControllerProvider.notifier)
|
await ref
|
||||||
.findNext(forward: false);
|
.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 ref
|
if (searchResult?.hasMatches ?? false) {
|
||||||
.read(findInPageControllerProvider.notifier)
|
await ref
|
||||||
.findNext();
|
.read(findInPageControllerProvider.notifier)
|
||||||
|
.findNext();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.clear),
|
icon: const Icon(Icons.clear),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
ref.read(findInPageControllerProvider.notifier).hide();
|
await ref.read(findInPageControllerProvider.notifier).hide();
|
||||||
|
|
||||||
await ref
|
|
||||||
.read(findInPageControllerProvider.notifier)
|
|
||||||
.clearMatches();
|
|
||||||
textController.clear();
|
textController.clear();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user