feat: requested selected item

This commit is contained in:
2025-05-27 11:23:47 +02:00
parent 426ce71be4
commit f4acf951d4
3 changed files with 103 additions and 37 deletions

View File

@@ -18,10 +18,10 @@ pub fn handle(action: Action, appState: *AppState, arena: std.mem.Allocator) !Ac
} else return error.NoCurrentLocation;
},
.SelectNext => {
return selectNextIndex(appState.currentTab, .Next);
return selectNextIndex(appState.currentTab, .Next, arena);
},
.SelectPrevious => {
return selectNextIndex(appState.currentTab, .Previous);
return selectNextIndex(appState.currentTab, .Previous, arena);
},
}
@@ -35,29 +35,38 @@ const SelectStep = enum {
PreviousPage,
};
fn selectNextIndex(currentTab: *Tab, step: SelectStep) ActionResult {
const index = blk: {
fn selectNextIndex(currentTab: *Tab, step: SelectStep, arena: std.mem.Allocator) !ActionResult {
const item = item: {
currentTab.currentItems.mutex.lock();
defer currentTab.currentItems.mutex.unlock();
const currentItems = currentTab.currentItems.data orelse return ActionResult.None;
if (currentTab.currentItem) |*currentItem| {
const index = indexOf(Arc(*models.Item), models.FullName, currentItems.items, currentItem, arcFullNameEql);
if (index) |i| {
break :blk switch (step) {
.Next => i +| 1,
.Previous => i -| 1,
.NextPage => i +| 8,
.PreviousPage => i +| 8,
};
const index = blk: {
if (currentTab.currentItem) |*currentItem| {
const index = indexOf(Arc(*models.Item), models.FullName, currentItems.items, currentItem, arcFullNameEql);
if (index) |i| {
break :blk switch (step) {
.Next => i +| 1,
.Previous => i -| 1,
.NextPage => i +| 8,
.PreviousPage => i +| 8,
};
}
}
}
break :blk 0;
break :blk 0;
};
const arc = currentItems.items[index];
const arc_copy = arc.retain();
defer if (arc_copy.releaseUnwrap()) |item| item.deinit();
break :item models.FullName{
.path = try arena.dupe(u8, arc_copy.value.*.fullName.path),
};
};
currentTab.selectItem(index) catch {
currentTab.selectItem(item) catch {
//TODO
};
return ActionResult.Handled;