╭ changed ────────────╮ │src/ui/Repo/Files.zig│ ╰─────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │16 // how many lines of a file's content one window shows before a "next" link. │ │17 const file_page = 5000; │ │18 │ │19 -// how many files in a directory get their content preloaded (windowed) so │ │20 -// selecting them shows contents without a reload. every entry is still listed;│ │21 -// files past this limit carry an "a:" link instead, so activating them reloads│ │22 -// the page with that file selected (and its content loaded as the selection). │ │23 -const max_preloaded = 100; │ │19 +// budget for the total bytes of file content preloaded (windowed) per page, │ │20 +// so selecting a preloaded file shows its contents without a reload. │ │21 +const max_preloaded_bytes = 2 * 1024 * 1024; │ │22 │ │23 // one entry in the directory currently being viewed. │ │24 pub const Entry = struct { │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────╮ │114 // another lookup. │ │115 const entries = try aa.alloc(Entry, tree_dir.entries.count()); │ │116 var i: usize = 0; │ │119 - var preloaded: usize = 0; │ │117 + var preloaded_bytes: usize = 0; │ │118 for ([_]bool{ true, false }) |want_dir| { │ │119 for (tree_dir.entries.keys(), tree_dir.entries.values()) |name, tree_entry| {│ │120 if (tree_entry.isTree() != want_dir) continue; │ ╰──────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │124 // their first window (for the in-page detail when selected). │ │125 const is_selected = if (selected_file) |sf| std.mem.eql(u8, sf, name) else false;│ │126 // the README always loads because it's the default selection. │ │129 - if (preloaded < max_preloaded or is_selected or isReadme(name)) { │ │130 - preloaded += 1; │ │127 + if (preloaded_bytes < max_preloaded_bytes or is_selected or isReadme(name)) { │ │128 const file_path = try childDir(aa, dir, name); │ │129 // the url's `line` is 1-based (0 = unset); the window │ │130 // index is 0-based. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │131 const window_start = if (is_selected) line -| 1 else 0; │ │132 const content = readFileContent(repo_kind, repo_opts, state, io, gpa, aa, file_path, tree_entry, window_start) catch│ │133 FileContent{ .lines = &.{} }; │ │134 + for (content.lines) |l| preloaded_bytes += l.len; │ │135 entry.lines = content.lines; │ │136 entry.is_binary = content.is_binary; │ │137 entry.window_start = window_start; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯