RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Keep directories first in every sort mode
Mel07131e161dd4
diff --git a/src/files/app_listing.zig b/src/files/app_listing.zigindex d3c824f..f95fb3d 100644--- a/src/files/app_listing.zig+++ b/src/files/app_listing.zig@@ -515,8 +515,8 @@ pub fn matches(self: *App, item: worker_mod.Item) bool {}pub fn lessThan(mode: Sort, a: ViewItem, b: ViewItem) bool {- // Sorting by date mixes folders and files; every other order groups folders first.- if (mode != .modified and mode != .modified_asc and a.is_dir != b.is_dir) return a.is_dir;+ // Keep directories ahead of files for every sort mode.+ if (a.is_dir != b.is_dir) return a.is_dir;if (mode == .size or mode == .size_asc) {if (a.is_dir and b.is_dir) {const a_calc = a.bytes >= 0;diff --git a/src/files/app_tests.zig b/src/files/app_tests.zigindex 28f8ffe..9a3a04b 100644--- a/src/files/app_tests.zig+++ b/src/files/app_tests.zig@@ -121,13 +121,17 @@ test "Unicode folder filtering and sorting retain folder size and date rules" {try app.search.text.appendSlice(app.allocator, query);try std.testing.expect(app.matches(source));}- var a: ViewItem = .{ .name = "z", .path = "/z", .sort_key = "a", .is_dir = true, .is_symlink = false, .is_broken = false, .bytes = 10, .mtime = 20, .icon_name = "" };+ var a: ViewItem = .{ .name = "z", .path = "/z", .sort_key = "a", .is_dir = true, .is_symlink = false, .is_broken = false, .bytes = 10, .mtime = 40, .icon_name = "" };var b: ViewItem = .{ .name = "a", .path = "/a", .sort_key = "z", .is_dir = false, .is_symlink = false, .is_broken = false, .bytes = 100, .mtime = 30, .icon_name = "" };try std.testing.expect(listing.lessThan(.name, a, b));try std.testing.expect(listing.lessThan(.size, a, b));- try std.testing.expect(listing.lessThan(.modified, b, a));+ try std.testing.expect(listing.lessThan(.modified, a, b));+ try std.testing.expect(!listing.lessThan(.modified, b, a));try std.testing.expect(listing.lessThan(.modified_asc, a, b));+ try std.testing.expect(!listing.lessThan(.modified_asc, b, a));a.is_dir = false;+ try std.testing.expect(listing.lessThan(.modified, a, b));+ try std.testing.expect(listing.lessThan(.modified_asc, b, a));try std.testing.expect(listing.lessThan(.name, a, b));try std.testing.expect(listing.lessThan(.name_desc, b, a));try std.testing.expect(listing.lessThan(.size, b, a));