Skip to content

Commit

Permalink
FluffyChat krille-chan#25: jump to selected search result on large sc…
Browse files Browse the repository at this point in the history
…reens
  • Loading branch information
carowebtec committed May 22, 2023
1 parent 601b851 commit 31202f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,21 @@ class ChatController extends State<Chat> {
inputFocus.requestFocus();
}

/*
* this function scrolls to event given by queryParameters, only if
* last route was search
*/
void scrollToEventAfterSearch(BuildContext context, String? from, String to) {
if (mounted && timeline != null) {
if (from != null && from.endsWith('/search')) {
final event = VRouter.of(context).queryParameters['event'];
if (event != null) {
scrollToEventId(event);
}
}
}
}

void scrollToEventId(String eventId) async {
var eventIndex = timeline!.events.indexWhere((e) => e.eventId == eventId);
if (eventIndex == -1) {
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class ChatView extends StatelessWidget {
redirector.stopRedirection();
}
},
afterUpdate: (BuildContext context, String? from, String to) async {
controller.scrollToEventAfterSearch(context, from, to);
},
child: GestureDetector(
onTapDown: controller.setReadMarker,
behavior: HitTestBehavior.opaque,
Expand Down
10 changes: 4 additions & 6 deletions lib/pages/chat_search/chat_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,10 @@ class ChatSearchController extends State<ChatSearch> {
}

void scrollToEventId(String eventId) {
VRouter.of(context).path.startsWith('/spaces/')
? VRouter.of(context).pop()
: VRouter.of(context).toSegments(
['rooms', roomId!],
queryParameters: {'event': eventId},
);
VRouter.of(context).toSegments(
['rooms', roomId!],
queryParameters: {'event': eventId},
);
}

void scrollToTop() {
Expand Down

0 comments on commit 31202f2

Please sign in to comment.