@tduncan / Cortana / commits / 47466d1

feat: prioritize selected model to the top of the list in picker and model components

abdulmominsakib committed Aug 8, 2026 at 22:26 UTC 47466d18c8b364e93b7b641854b89db50309df67
2 files changed +27
lib/features/models/components/model_list.dart
+10
@@ -85,6 +85,16 @@ class _ModelListState extends ConsumerState<ModelList> {
85 return ctx != 0 ? ctx : byName(a, b);
86 });
87 }
88 +
89 + final selectedId = widget.selectedModelId;
90 + if (selectedId != null) {
91 + final selectedIndex = sorted.indexWhere((m) => m.id == selectedId);
92 + if (selectedIndex > 0) {
93 + final selected = sorted.removeAt(selectedIndex);
94 + sorted.insert(0, selected);
95 + }
96 + }
97 +
98 return sorted;
99 }
100
lib/features/on_device/components/on_device_picker_section.dart
+17
@@ -106,6 +106,23 @@ class OnDevicePickerSection extends ConsumerWidget {
106 .where((model) => !model.isImported)
107 .toList();
108
109 + if (selectedModelId != null) {
110 + final impIndex = importedModels.indexWhere(
111 + (m) => m.id == selectedModelId,
112 + );
113 + if (impIndex > 0) {
114 + final selected = importedModels.removeAt(impIndex);
115 + importedModels.insert(0, selected);
116 + }
117 + final dlIndex = downloadableModels.indexWhere(
118 + (m) => m.id == selectedModelId,
119 + );
120 + if (dlIndex > 0) {
121 + final selected = downloadableModels.removeAt(dlIndex);
122 + downloadableModels.insert(0, selected);
123 + }
124 + }
125 +
126 Widget buildTile(OnDeviceModel model) {
127 final isDownloaded = downloadedIds.contains(model.id);
128 final isLoaded = engineState.loadedModelId == model.id;