(props: {
file: ReturnType<typeof useFile>
tabs: () => ReturnType<ReturnType<typeof useLayout>["tabs"]>
language: ReturnType<typeof useLanguage>
})
| 137 | } |
| 138 | |
| 139 | function createFileEntries(props: { |
| 140 | file: ReturnType<typeof useFile> |
| 141 | tabs: () => ReturnType<ReturnType<typeof useLayout>["tabs"]> |
| 142 | language: ReturnType<typeof useLanguage> |
| 143 | }) { |
| 144 | const tabState = createSessionTabs({ |
| 145 | tabs: props.tabs, |
| 146 | pathFromTab: props.file.pathFromTab, |
| 147 | normalizeTab: (tab) => (tab.startsWith("file://") ? props.file.tab(tab) : tab), |
| 148 | }) |
| 149 | const recent = createMemo(() => { |
| 150 | const all = tabState.openedTabs() |
| 151 | const active = tabState.activeFileTab() |
| 152 | const order = active ? [active, ...all.filter((item) => item !== active)] : all |
| 153 | const seen = new Set<string>() |
| 154 | const category = props.language.t("palette.group.files") |
| 155 | const items: Entry[] = [] |
| 156 | |
| 157 | for (const item of order) { |
| 158 | const path = props.file.pathFromTab(item) |
| 159 | if (!path) continue |
| 160 | if (seen.has(path)) continue |
| 161 | seen.add(path) |
| 162 | items.push(createFileEntry(path, category)) |
| 163 | } |
| 164 | |
| 165 | return items.slice(0, ENTRY_LIMIT) |
| 166 | }) |
| 167 | |
| 168 | const root = createMemo(() => { |
| 169 | const category = props.language.t("palette.group.files") |
| 170 | const nodes = props.file.tree.children("") |
| 171 | const paths = nodes |
| 172 | .filter((node) => node.type === "file") |
| 173 | .map((node) => node.path) |
| 174 | .sort((a, b) => a.localeCompare(b)) |
| 175 | return paths.slice(0, ENTRY_LIMIT).map((path) => createFileEntry(path, category)) |
| 176 | }) |
| 177 | |
| 178 | return { recent, root } |
| 179 | } |
| 180 | |
| 181 | function createSessionEntries(props: { |
| 182 | workspaces: () => string[] |
no test coverage detected