[client] Clear selection on escape

This commit is contained in:
Abhishek Shroff
2024-11-05 08:27:49 +05:30
parent 9d9203a48f
commit 7376acae38
4 changed files with 8 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ enum SelectionMode {
range,
multi,
toggle,
none,
}
class FocusUpIntent extends Intent {

View File

@@ -38,7 +38,7 @@ class ExplorerActions extends StatelessWidget {
return null;
}),
DismissIntent: CallbackAction<DismissIntent>(onInvoke: (i) {
context.read<ExplorerViewController>().updateSelection((i) => i, SelectionMode.single, true);
context.read<ExplorerViewController>().updateSelection((i) => i, SelectionMode.none, true);
return null;
}),
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: (i) {

View File

@@ -21,6 +21,7 @@ class ExplorerViewState {
String? get focusId => focussed?.id;
Iterable<Resource> get selected => resources.where((r) => selectedIds.contains(r.id));
Resource? get selectedSingle => selectedIds.length != 1 ? null : resources.where((r) => selectedIds.contains(r.id)).firstOrNull;
Resource? get focussedIfSelected => selectedIds.isEmpty ? null : focussed;
const ExplorerViewState({
this.folder,
@@ -127,6 +128,10 @@ class ExplorerViewController extends StateNotifier<ExplorerViewState> {
}
selectionStartIndex = index;
break;
case SelectionMode.none:
selectedIds = const {};
selectionStartIndex = index;
break;
case SelectionMode.multi:
break;
}

View File

@@ -15,7 +15,7 @@ class ResourceInfoView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final resource = context.select<ExplorerViewState, Resource?>((state) {
return state.focussed ?? state.folder;
return state.focussedIfSelected ?? state.folder;
});
if (resource == null) {