MCPcopy Create free account
hub / github.com/experdot/pointer / getHistoryMenuItems

Function getHistoryMenuItems

src/renderer/src/components/layout/Tabs/index.tsx:221–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219
220 // 历史记录右键菜单
221 const getHistoryMenuItems = (): MenuProps['items'] => {
222 const pages = usePagesStore.getState().pages
223
224 // 获取历史条目的标题:优先从打开的 tab 获取,其次从 pages 获取
225 const getEntryTitle = (entry: (typeof history)[number]): string => {
226 const tab = tabs.find((t) => t.id === entry.tabId)
227 if (tab?.title) return tab.title
228 if (entry.dataId) {
229 const page = pages.find((p) => p.id === entry.dataId)
230 if (page?.name) return page.name
231 }
232 return '未知页面'
233 }
234
235 const historyItems: MenuProps['items'] = history
236 .map((entry, index) => ({ entry, index }))
237 .toReversed()
238 .map(({ entry, index }) => {
239 const isCurrent = index === historyIndex
240 return {
241 key: `history-${index}`,
242 label: (
243 <span style={{ fontWeight: isCurrent ? 'bold' : 'normal' }}>
244 {isCurrent ? '→ ' : ''}
245 {getEntryTitle(entry)}
246 </span>
247 ),
248 onClick: () => navigateToHistoryIndex(index)
249 }
250 })
251
252 return [
253 {
254 key: 'clear',
255 label: '清空导航历史',
256 icon: <DeleteOutlined />,
257 danger: true,
258 onClick: clearHistory
259 },
260 { type: 'divider' },
261 ...historyItems
262 ]
263 }
264
265 if (tabs.length === 0) return <></>
266

Callers 1

TabsFunction · 0.85

Calls 1

getEntryTitleFunction · 0.85

Tested by

no test coverage detected