Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/settings/l10n/settings_catalogs.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/settings/l10n/settings_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@
"סגור ספר נוכחי": "Close the Current Tab",
"סגור כל הספרים": "Close all Tabs",
"פתח כרטיסייה אחרונה שנסגרה": "Reopen the Last Closed Tab",
"חזרה לכרטיסייה האחרונה שנצפתה": "Return to the Last Viewed Tab",
"קיצור לחזרה לכרטיסייה האחרונה שנצפתה": "Shortcut to return to the last viewed tab",
"מעבר לכרטיסייה שהייתה פעילה לפני הנוכחית": "Switch to the tab that was active before the current one",
"פתח/סגור חלונית ניווט": "Toggle the Navigation Panel",
"פתח/סגור חלונית מפרשים": "Toggle the Meforshim Panel",
"החלף מצב תצוגה (PDF/טקסט)": "Switch View (PDF/text)",
Expand Down
18 changes: 18 additions & 0 deletions lib/settings/tabs/shortcuts_settings_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class ShortcutsSettingsTab extends StatefulWidget {
expandSection: 'key-shortcut-close-all-tabs',
keywords: ['סגור הכל', 'ctrl+shift+w', 'מקלדת'],
),
SettingsSearchEntry(
id: 'shortcuts.book.last_viewed',
title: 'קיצור לחזרה לכרטיסייה האחרונה שנצפתה',
subtitle: 'מעבר לכרטיסייה שהייתה פעילה לפני הנוכחית',
tab: SettingsTab.shortcuts,
cardId: 'shortcuts.book',
expandSection: ShortcutValidator.lastViewedTabKey,
keywords: ['חזרה', 'כרטיסייה קודמת', 'טאב אחרון', 'מקלדת'],
),
SettingsSearchEntry(
id: 'shortcuts.book.restore_closed',
title: 'קיצור לפתיחת כרטיסייה אחרונה שנסגרה',
Expand Down Expand Up @@ -1027,6 +1036,15 @@ class _ShortcutsSettingsTabState extends State<ShortcutsSettingsTab> {
icon: FluentIcons.dismiss_24_regular,
allShortcuts: _shortcutsList,
),
_ShortcutTile(
settingKey: ShortcutValidator.lastViewedTabKey,
label: context.settingsText('חזרה לכרטיסייה האחרונה שנצפתה'),
subtitle: context.settingsText(
'מעבר לכרטיסייה שהייתה פעילה לפני הנוכחית',
),
icon: FluentIcons.arrow_swap_24_regular,
allShortcuts: _shortcutsList,
),
_ShortcutTile(
settingKey: 'key-shortcut-restore-closed-tab',
label: context.settingsText('פתח כרטיסייה אחרונה שנסגרה'),
Expand Down
10 changes: 10 additions & 0 deletions lib/shortcuts/keyboard_shortcuts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ class _KeyboardShortcutsState extends State<KeyboardShortcuts> {
final restoreClosedTabShortcut = shortcutOf(
'key-shortcut-restore-closed-tab',
);
final lastViewedTabShortcut = shortcutOf(
ShortcutValidator.lastViewedTabKey,
);
final searchTabsShortcut = shortcutOf('key-shortcut-search-tabs');
final readingScreenShortcut = shortcutOf(
'key-shortcut-open-reading-screen',
Expand Down Expand Up @@ -490,6 +493,13 @@ class _KeyboardShortcutsState extends State<KeyboardShortcuts> {
return KeyEventResult.handled;
}

if (isReadingScreen &&
lastViewedTabShortcut.isNotEmpty &&
ShortcutHelper.matchesShortcut(event, lastViewedTabShortcut)) {
context.read<TabsBloc>().add(NavigateToLastViewedTab());
return KeyEventResult.handled;
}

// שחזור כרטיסייה או חלון זמין מכל מסך ומחזיר למסך העיון.
if (ShortcutHelper.matchesShortcut(event, restoreClosedTabShortcut)) {
// כמו בדפדפן: קודם כרטיסיה שנסגרה, ורק אם אין כזו — חלון שנסגר.
Expand Down
6 changes: 6 additions & 0 deletions lib/shortcuts/shortcut_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ShortcutValidator {
/// פתיחת רשימת קיצורי המקשים (הגדרות ← קיצורים), ללא ברירת מחדל.
static const String openShortcutsListKey = 'key-shortcut-open-shortcuts-list';

/// חזרה לכרטיסייה האחרונה שנצפתה — אופציונלי, ללא ברירת מחדל.
static const String lastViewedTabKey = 'key-shortcut-last-viewed-tab';

/// פתיחת חלון אוצריא נוסף — פעיל רק בפלטפורמה שתומכת בריבוי חלונות.
static const String openNewWindowKey = 'key-shortcut-open-new-window';

Expand Down Expand Up @@ -223,6 +226,7 @@ class ShortcutValidator {
'key-shortcut-close-tab',
'key-shortcut-close-all-tabs',
'key-shortcut-restore-closed-tab',
lastViewedTabKey,
'key-shortcut-search-tabs',
'key-shortcut-open-reading-screen',
'key-shortcut-open-new-search',
Expand Down Expand Up @@ -306,6 +310,7 @@ class ShortcutValidator {
'key-shortcut-close-tab': 'ctrl+w',
'key-shortcut-close-all-tabs': 'ctrl+shift+w',
'key-shortcut-restore-closed-tab': 'ctrl+shift+t',
lastViewedTabKey: '',
'key-shortcut-search-tabs': 'ctrl+shift+a',
'key-shortcut-open-reading-screen': 'ctrl+r',
'key-shortcut-open-new-search': 'ctrl+shift+f',
Expand Down Expand Up @@ -381,6 +386,7 @@ class ShortcutValidator {
'key-shortcut-close-tab': 'סגור ספר נוכחי',
'key-shortcut-close-all-tabs': 'סגור כל הספרים',
'key-shortcut-restore-closed-tab': 'פתח כרטיסייה אחרונה שנסגרה',
lastViewedTabKey: 'חזרה לכרטיסייה האחרונה שנצפתה',
'key-shortcut-search-tabs': 'חיפוש כרטיסיות',
'key-shortcut-open-reading-screen': 'עיון',
'key-shortcut-open-new-search': 'חיפוש חדש בכל הספרים',
Expand Down
46 changes: 35 additions & 11 deletions lib/tabs/bloc/tabs_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:collection';
import 'dart:math';

import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -61,7 +62,7 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
final Future<OpenedTab> Function(OpenedTab tab) _withCompanion;
final List<_ClosedTabEntry> _recentlyClosedTabs = <_ClosedTabEntry>[];

/// מתי כל כרטיסיה הוצגה לאחרונה, כדי שסגירת הפעילה תחזור לקודמתה.
/// מתי כל כרטיסיה הוצגה לאחרונה, לחזרה לקודמתה ולסגירת הפעילה.
final Expando<int> _lastViewedAt = Expando<int>();
int _viewClock = 0;

Expand Down Expand Up @@ -282,6 +283,10 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
on<CloseOtherTabs>(_onCloseOtherTabs, transformer: sequential());
on<CloneTab>(_onCloneTab, transformer: sequential());
on<MoveTab>(_onMoveTab, transformer: sequential());
on<NavigateToLastViewedTab>(
_onNavigateToLastViewedTab,
transformer: sequential(),
);
on<NavigateToNextTab>(_onNavigateToNextTab, transformer: sequential());
on<NavigateToPreviousTab>(
_onNavigateToPreviousTab,
Expand Down Expand Up @@ -1413,16 +1418,8 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
if (current != null && !removed.contains(current)) {
return remaining.indexOf(current);
}
var best = -1;
var bestViewedAt = 0;
for (var i = 0; i < remaining.length; i++) {
final viewedAt = _lastViewedAt[remaining[i]];
if (viewedAt != null && viewedAt > bestViewedAt) {
best = i;
bestViewedAt = viewedAt;
}
}
if (best != -1) return best;
final lastViewed = _lastViewedTab(remaining);
if (lastViewed != null) return remaining.indexOf(lastViewed);
final removedBefore = state.tabs
.take(state.currentTabIndex)
.where(removed.contains)
Expand Down Expand Up @@ -1728,6 +1725,33 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
_scheduleSave(newTabs, targetIndex);
}

OpenedTab? _lastViewedTab(Iterable<OpenedTab> tabs) {
OpenedTab? latest;
var bestViewedAt = 0;
for (final tab in tabs) {
final viewedAt = _lastViewedAt[tab];
if (viewedAt != null && viewedAt > bestViewedAt) {
latest = tab;
bestViewedAt = viewedAt;
}
}
return latest;
}

Future<void> _onNavigateToLastViewedTab(
NavigateToLastViewedTab event,
Emitter<TabsState> emit,
) async {
final tabsToSave = state.tabs;
final target = _lastViewedTab(
tabsToSave.where((tab) => !identical(tab, state.currentTab)),
);
if (target == null) return;
final newIndex = tabsToSave.indexOf(target);
emit(state.copyWith(currentTabIndex: newIndex));
await _saveCurrentTabIndex(tabsToSave, newIndex);
}

Future<void> _onNavigateToNextTab(
NavigateToNextTab event,
Emitter<TabsState> emit,
Expand Down
2 changes: 2 additions & 0 deletions lib/tabs/bloc/tabs_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class MoveTab extends TabsEvent {
List<Object?> get props => [tab, newIndex];
}

class NavigateToLastViewedTab extends TabsEvent {}

class NavigateToNextTab extends TabsEvent {}

class NavigateToPreviousTab extends TabsEvent {}
Expand Down
20 changes: 19 additions & 1 deletion test/settings/shortcuts_settings_search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() {
entry.id != 'shortcuts.reset' && entry.id != 'shortcuts.fixed',
)
.toList();
expect(entries, hasLength(53));
expect(entries, hasLength(54));
expect(
entries.map((entry) => entry.expandSection).toSet(),
hasLength(entries.length),
Expand Down Expand Up @@ -85,4 +85,22 @@ void main() {
contains(entry),
);
});

test('חיפוש הכרטיסייה האחרונה מפנה לקיצור האופציונלי', () {
final entry = ShortcutsSettingsTab.searchEntries.singleWhere(
(entry) => entry.id == 'shortcuts.book.last_viewed',
);
const key = ShortcutValidator.lastViewedTabKey;
expect(entry.expandSection, key);
expect(ShortcutValidator.defaultShortcuts[key], isEmpty);
for (final (query, language) in [
('טאב אחרון', SettingsLanguage.hebrew),
('last viewed tab', SettingsLanguage.english),
]) {
expect(
SettingsSearchIndex.search(query, language: language),
contains(entry),
);
}
});
}
90 changes: 88 additions & 2 deletions test/shortcuts/keyboard_shortcuts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import 'package:otzaria/widgets/dialogs/app_dialog_frame.dart';
import 'package:otzaria/widgets/widgets_exports.dart' show ActionButton;
import 'package:otzaria_report_contract/otzaria_report_contract.dart';
import 'package:provider/provider.dart';

import '../app_report/app_report_test_fakes.dart';
import '../helpers/memory_settings_cache.dart';

Expand Down Expand Up @@ -1137,7 +1138,7 @@ void main() {
});
});

group('KeyboardShortcuts - Ctrl+1..9 מעבר לטאב', () {
group('KeyboardShortcuts - ניווט כרטיסיות', () {
late MockSettingsBloc settingsBlocLocal;
late StreamController<SettingsState> settingsControllerLocal;

Expand Down Expand Up @@ -1165,10 +1166,11 @@ void main() {
WidgetTester tester,
int tabCount, {
VoidCallback? onFindRefRequested,
Screen screen = Screen.reading,
}) async {
final tabsBloc = TabsBloc(repository: _FakeTabsRepository());
final historyBloc = _StubHistoryBloc();
final navigationBloc = _StubNavigationBloc();
final navigationBloc = _StubNavigationBloc(screen);
addTearDown(() async {
await tabsBloc.close();
await historyBloc.close();
Expand Down Expand Up @@ -1211,6 +1213,90 @@ void main() {
await tester.pump();
}

testWidgets('קיצור חזרה לכרטיסייה האחרונה עובר הלוך ושוב', (
tester,
) async {
whenListen(
settingsBlocLocal,
settingsControllerLocal.stream,
initialState: SettingsState.initial().copyWith(
shortcuts: const {'key-shortcut-last-viewed-tab': 'ctrl+j'},
),
);
final tabsBloc = await pumpWithTabs(tester, 3);
tabsBloc.add(const SetCurrentTab(0));
await tester.pump();
tabsBloc.add(const SetCurrentTab(2));
await tester.pump();

await sendCtrl(tester, LogicalKeyboardKey.keyJ);
expect(tabsBloc.state.currentTabIndex, 0);
await sendCtrl(tester, LogicalKeyboardKey.keyJ);
expect(tabsBloc.state.currentTabIndex, 2);

// Ctrl+Tab ממשיך לעבור לפי סדר הכרטיסיות.
await sendCtrl(tester, LogicalKeyboardKey.tab);
await sendCtrl(tester, LogicalKeyboardKey.tab);
expect(tabsBloc.state.currentTabIndex, 1);
});

testWidgets('קיצור חזרה ריק אינו מופעל', (tester) async {
whenListen(
settingsBlocLocal,
settingsControllerLocal.stream,
initialState: SettingsState.initial().copyWith(
shortcuts: const {'key-shortcut-last-viewed-tab': ''},
),
);
final tabsBloc = await pumpWithTabs(tester, 3);

await sendCtrl(tester, LogicalKeyboardKey.keyJ);

expect(tabsBloc.state.currentTabIndex, 2);
});

testWidgets('קיצור חזרה לכרטיסייה מושבת מחוץ למסך העיון', (
tester,
) async {
whenListen(
settingsBlocLocal,
settingsControllerLocal.stream,
initialState: SettingsState.initial().copyWith(
shortcuts: const {'key-shortcut-last-viewed-tab': 'ctrl+j'},
),
);
final tabsBloc = await pumpWithTabs(tester, 3, screen: Screen.library);

await sendCtrl(tester, LogicalKeyboardKey.keyJ);

expect(tabsBloc.state.currentTabIndex, 2);
});

testWidgets('קיצור חזרה לכרטיסייה מושבת כשדיאלוג פתוח', (
tester,
) async {
whenListen(
settingsBlocLocal,
settingsControllerLocal.stream,
initialState: SettingsState.initial().copyWith(
shortcuts: const {'key-shortcut-last-viewed-tab': 'ctrl+j'},
),
);
final tabsBloc = await pumpWithTabs(tester, 3);
unawaited(
showDialog<void>(
context: tester.element(find.byType(Scaffold)),
builder: (_) => const Dialog(child: Text('דיאלוג פתוח')),
),
);
await tester.pumpAndSettle();

await sendCtrl(tester, LogicalKeyboardKey.keyJ);

expect(tabsBloc.state.currentTabIndex, 2);
expect(find.text('דיאלוג פתוח'), findsOneWidget);
});

for (final (key, shortcut) in [
(LogicalKeyboardKey.tab, 'ctrl+tab'),
(LogicalKeyboardKey.digit3, 'ctrl+3'),
Expand Down
Loading
Loading