Skip to content

Commit bc8f430

Browse files
authored
Merge pull request #588 from Yumiue/html_progress
refator(web):改变web布局和字体
2 parents ddcf1f2 + 77f8bd4 commit bc8f430

8 files changed

Lines changed: 75 additions & 59 deletions

File tree

web/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"verify:electron-preload": "node scripts/verify-electron-preload.js"
1919
},
2020
"dependencies": {
21+
"@fontsource/jetbrains-mono": "^5.2.8",
2122
"@monaco-editor/react": "^4.7.0",
2223
"electron-updater": "^6.8.3",
2324
"lucide-react": "^0.468.0",

web/src/components/panels/CodePreviewEditor.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ vi.mock('@monaco-editor/react', () => ({
1414
value: string
1515
language: string
1616
theme: string
17-
options: { readOnly?: boolean }
17+
options: { readOnly?: boolean; fontFamily?: string }
1818
}) => (
1919
<div
2020
data-testid="monaco-editor"
@@ -23,6 +23,7 @@ vi.mock('@monaco-editor/react', () => ({
2323
data-language={language}
2424
data-theme={theme}
2525
data-readonly={String(Boolean(options.readOnly))}
26+
data-font-family={options.fontFamily}
2627
/>
2728
),
2829
}))
@@ -52,6 +53,7 @@ describe('CodePreviewEditor', () => {
5253
expect(editor).toHaveAttribute('data-language', 'go')
5354
expect(editor).toHaveAttribute('data-theme', 'vs-dark')
5455
expect(editor).toHaveAttribute('data-readonly', 'true')
56+
expect(editor).toHaveAttribute('data-font-family', 'var(--font-mono)')
5557
})
5658

5759
it('uses the explicit language when provided', () => {

web/src/components/panels/FileChangePanel.test.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
2+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
33
import FileChangePanel from './FileChangePanel'
44
import { CHANGES_PREVIEW_TAB_ID, GIT_DIFF_PREVIEW_TAB_ID, useUIStore } from '@/stores/useUIStore'
55

@@ -323,6 +323,19 @@ describe('FileChangePanel', () => {
323323
})
324324

325325
it('opens a git diff file tab from the fixed git diff view', async () => {
326+
mockGatewayAPI.readGitDiffFile.mockResolvedValueOnce({
327+
payload: {
328+
path: 'src/main.go',
329+
status: 'modified',
330+
old_path: 'src/legacy.go',
331+
encoding: 'utf-8',
332+
original_content: 'before',
333+
modified_content: 'after',
334+
size_original: 6,
335+
size_modified: 5,
336+
},
337+
})
338+
326339
render(<FileChangePanel />)
327340

328341
fireEvent.click(screen.getByTestId(`preview-tab-${GIT_DIFF_PREVIEW_TAB_ID}`))
@@ -342,6 +355,17 @@ describe('FileChangePanel', () => {
342355
expect(preview).toHaveAttribute('data-path', 'src/main.go')
343356
expect(preview).toHaveAttribute('data-side-by-side', 'true')
344357
expect(preview.textContent).toContain('before::after')
358+
359+
const gitDiffHeader = screen.getByTestId('git-diff-file-preview-header')
360+
const gitDiffPath = within(gitDiffHeader).getByTestId('git-diff-file-preview-path')
361+
expect(gitDiffPath.textContent).toBe('src/main.go')
362+
expect(gitDiffPath).toHaveAttribute('title', 'src/main.go')
363+
expect(gitDiffPath).toHaveStyle({
364+
whiteSpace: 'nowrap',
365+
overflow: 'hidden',
366+
textOverflow: 'ellipsis',
367+
})
368+
expect(gitDiffHeader.textContent?.trim()).toBe('src/main.go')
345369
})
346370

347371
it('renders file preview tabs in the secondary chip row instead of mixing them into the primary switcher', () => {
@@ -365,6 +389,9 @@ describe('FileChangePanel', () => {
365389
title: 'main.go',
366390
closable: true,
367391
path: 'cmd/neocode/main.go',
392+
size: 1024,
393+
encoding: 'utf-8',
394+
mod_time: '2026-05-08T10:53:48Z',
368395
content: 'package main',
369396
loading: false,
370397
loaded: true,
@@ -553,6 +580,16 @@ describe('FileChangePanel', () => {
553580
expect(preview).toHaveAttribute('data-path', 'cmd/neocode/main.go')
554581
expect(preview).toHaveAttribute('data-theme', 'light')
555582
expect(preview.textContent).toContain('package main')
583+
const fileHeader = screen.getByTestId('file-preview-header')
584+
const filePath = within(fileHeader).getByTestId('file-preview-path')
585+
expect(filePath.textContent).toBe('cmd/neocode/main.go')
586+
expect(filePath).toHaveAttribute('title', 'cmd/neocode/main.go')
587+
expect(filePath).toHaveStyle({
588+
whiteSpace: 'nowrap',
589+
overflow: 'hidden',
590+
textOverflow: 'ellipsis',
591+
})
592+
expect(fileHeader.textContent?.trim()).toBe('cmd/neocode/main.go')
556593
})
557594

558595
it('uses theme variables instead of fixed diff colors in light mode', () => {

web/src/components/panels/FileChangePanel.tsx

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,6 @@ function getContextPreviewTabID(activeTab: PreviewTab | undefined) {
117117
return activeTab.id
118118
}
119119

120-
function formatPreviewMeta(tab: FilePreviewTab) {
121-
const segments: string[] = []
122-
if (typeof tab.size === 'number') {
123-
segments.push(`${tab.size} B`)
124-
}
125-
if (tab.encoding) {
126-
segments.push(tab.encoding)
127-
}
128-
if (tab.mod_time) {
129-
segments.push(tab.mod_time)
130-
}
131-
return segments.join(' · ')
132-
}
133-
134-
function formatGitDiffMeta(tab: GitDiffFilePreviewTab) {
135-
const segments: string[] = []
136-
if (typeof tab.size_original === 'number') {
137-
segments.push(`原始 ${tab.size_original} B`)
138-
}
139-
if (typeof tab.size_modified === 'number') {
140-
segments.push(`当前 ${tab.size_modified} B`)
141-
}
142-
if (tab.encoding) {
143-
segments.push(tab.encoding)
144-
}
145-
return segments.join(' · ')
146-
}
147-
148120
function DiffLineView({ line }: { line: DiffLine }) {
149121
const lineStyles: Record<DiffLine['type'], CSSProperties> = {
150122
add: { color: 'var(--diff-add-text)', background: 'var(--diff-add-bg)' },
@@ -313,7 +285,6 @@ function PreviewFallback({ message = '正在加载代码编辑器...' }: { messa
313285

314286
function FilePreviewView({ tab }: { tab: FilePreviewTab }) {
315287
const theme = useUIStore((state) => state.theme)
316-
const meta = formatPreviewMeta(tab)
317288

318289
let body = null
319290
if (tab.loading) {
@@ -336,10 +307,8 @@ function FilePreviewView({ tab }: { tab: FilePreviewTab }) {
336307

337308
return (
338309
<div style={styles.viewContainer}>
339-
<div style={styles.viewHeader}>
340-
<span style={styles.viewTitle}>{tab.title}</span>
341-
<div style={styles.previewPath}>{tab.path}</div>
342-
{meta && <div style={styles.previewMeta}>{meta}</div>}
310+
<div style={styles.viewHeader} data-testid="file-preview-header">
311+
<div style={styles.previewPath} data-testid="file-preview-path" title={tab.path}>{tab.path}</div>
343312
</div>
344313
{body}
345314
</div>
@@ -349,8 +318,6 @@ function FilePreviewView({ tab }: { tab: FilePreviewTab }) {
349318
function GitDiffFileView({ tab }: { tab: GitDiffFilePreviewTab }) {
350319
const theme = useUIStore((state) => state.theme)
351320
const changesPanelWidth = useUIStore((state) => state.changesPanelWidth)
352-
const meta = formatGitDiffMeta(tab)
353-
const statusMeta = gitDiffStatusMeta[tab.status]
354321

355322
let body = null
356323
if (tab.loading) {
@@ -377,14 +344,8 @@ function GitDiffFileView({ tab }: { tab: GitDiffFilePreviewTab }) {
377344

378345
return (
379346
<div style={styles.viewContainer}>
380-
<div style={styles.viewHeader}>
381-
<div style={styles.titleRow}>
382-
<span style={styles.viewTitle}>{tab.title}</span>
383-
<span style={{ ...styles.statusPill, color: statusMeta.color, background: statusMeta.bg }}>{statusMeta.label}</span>
384-
</div>
385-
<div style={styles.previewPath}>{tab.path}</div>
386-
{tab.old_path && <div style={styles.previewSubPath}>原路径: {tab.old_path}</div>}
387-
{meta && <div style={styles.previewMeta}>{meta}</div>}
347+
<div style={styles.viewHeader} data-testid="git-diff-file-preview-header">
348+
<div style={styles.previewPath} data-testid="git-diff-file-preview-path" title={tab.path}>{tab.path}</div>
388349
</div>
389350
{body}
390351
</div>
@@ -931,16 +892,21 @@ const styles: Record<string, CSSProperties> = {
931892
display: 'flex',
932893
flexDirection: 'column',
933894
overflow: 'hidden',
895+
padding: '8px 10px 0',
934896
},
935897
viewContainer: {
936898
display: 'flex',
937899
flexDirection: 'column',
938900
flex: 1,
939901
minHeight: 0,
940902
overflow: 'hidden',
903+
background: 'var(--bg-primary)',
904+
border: '1px solid var(--border-primary)',
905+
borderRadius: 'var(--radius-md)',
906+
boxShadow: 'var(--shadow-surface)',
941907
},
942908
viewHeader: {
943-
padding: '12px 14px',
909+
padding: '8px 10px',
944910
borderBottom: '1px solid var(--border-primary)',
945911
flexShrink: 0,
946912
},
@@ -984,7 +950,7 @@ const styles: Record<string, CSSProperties> = {
984950
flex: 1,
985951
minHeight: 0,
986952
overflow: 'auto',
987-
padding: 12,
953+
padding: 10,
988954
},
989955
contentStack: {
990956
display: 'flex',
@@ -1143,22 +1109,19 @@ const styles: Record<string, CSSProperties> = {
11431109
color: 'var(--text-tertiary)',
11441110
fontSize: 12,
11451111
fontFamily: 'var(--font-ui)',
1146-
padding: 20,
1112+
padding: 16,
11471113
textAlign: 'center',
11481114
},
11491115
previewPath: {
1150-
marginTop: 8,
1116+
marginTop: 0,
11511117
color: 'var(--text-secondary)',
11521118
fontSize: 12,
11531119
fontFamily: 'var(--font-ui)',
1154-
wordBreak: 'break-all',
1155-
},
1156-
previewSubPath: {
1157-
marginTop: 4,
1158-
color: 'var(--text-tertiary)',
1159-
fontSize: 11,
1160-
fontFamily: 'var(--font-ui)',
1161-
wordBreak: 'break-all',
1120+
minWidth: 0,
1121+
lineHeight: '18px',
1122+
whiteSpace: 'nowrap',
1123+
overflow: 'hidden',
1124+
textOverflow: 'ellipsis',
11621125
},
11631126
previewMeta: {
11641127
marginTop: 6,

web/src/components/panels/GitDiffPreviewEditor.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ vi.mock('@monaco-editor/react', () => ({
1414
modified: string
1515
language: string
1616
theme: string
17-
options: { renderSideBySide?: boolean; lineNumbers?: string }
17+
options: { renderSideBySide?: boolean; lineNumbers?: string; fontFamily?: string }
1818
}) => (
1919
<div
2020
data-testid="monaco-diff-editor"
2121
data-language={language}
2222
data-theme={theme}
2323
data-side-by-side={String(Boolean(options.renderSideBySide))}
2424
data-line-numbers={options.lineNumbers}
25+
data-font-family={options.fontFamily}
2526
>
2627
{original}::{modified}
2728
</div>
@@ -45,6 +46,7 @@ describe('GitDiffPreviewEditor', () => {
4546
expect(editor).toHaveAttribute('data-theme', 'vs-dark')
4647
expect(editor).toHaveAttribute('data-side-by-side', 'true')
4748
expect(editor).toHaveAttribute('data-line-numbers', 'on')
49+
expect(editor).toHaveAttribute('data-font-family', 'var(--font-mono)')
4850
expect(editor.textContent).toContain('before::after')
4951
})
5052

web/src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
/* Typography */
5555
--font-ui: system-ui, -apple-system, 'SF Pro Text', 'SF Pro Display', sans-serif;
56-
--font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
56+
--font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace;
5757

5858
/* Spacing scale (4px base) */
5959
--space-1: 4px;

web/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom/client'
3+
import '@fontsource/jetbrains-mono/400.css'
34
import App from './App'
45
import { RuntimeProvider } from './context/RuntimeProvider'
56
import './index.css'

0 commit comments

Comments
 (0)