File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type { Chunk, LogDocument } from '@/types/log';
77import { buildLogDocument } from '@/io/import/parser' ;
88import { dispatchAdapter } from '@/io/import/importAdapters' ;
99import { tryParseProjectFile } from '@/io/localStorage/project' ;
10+ import { stripFileExtension } from '@/utils/fileName' ;
1011import { useProjectManager } from './useProjectManager' ;
1112
1213// 统一换行符并移除0宽字符,防止正则崩掉
@@ -133,7 +134,10 @@ export function useFileImport() {
133134 }
134135
135136 const documents = await importFiles (
136- fileEntries . map ( ( e ) => ( { name : e . file . name , text : e . text } ) ) ,
137+ fileEntries . map ( ( e ) => ( {
138+ name : stripFileExtension ( e . file . name ) ,
139+ text : e . text ,
140+ } ) ) ,
137141 logStore . documents . length ,
138142 ) ;
139143
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { ColorRule, ViewSettings } from '@/types/style';
22import type { LogDocument , MessageFilter } from '@/types/log' ;
33import { isRoleType } from '@/types/log' ;
44import type { ProjectFile } from '@/types/project' ;
5+ import { stripFileExtension } from '@/utils/fileName' ;
56import { generateId } from '@/utils/id' ;
67
78export const PROJECT_FILE_VERSION = 1 as const ;
@@ -240,7 +241,7 @@ function normalizeDocuments(rawDocuments: unknown): LogDocument[] {
240241 docId : typeof doc . docId === 'string' ? doc . docId : generateId ( ) ,
241242 docName :
242243 typeof doc . docName === 'string'
243- ? doc . docName
244+ ? stripFileExtension ( doc . docName )
244245 : `Document-${ docIndex + 1 } ` ,
245246 docIndex :
246247 typeof doc . docIndex === 'number' ? doc . docIndex : docIndex ,
@@ -402,7 +403,7 @@ export function normalizeProjectFile(
402403 : rawProject . projectId ;
403404 const projectName =
404405 typeof rawProject . projectName === 'string'
405- ? rawProject . projectName . trim ( )
406+ ? stripFileExtension ( rawProject . projectName )
406407 : '' ;
407408 const time =
408409 typeof rawProject . time === 'string' &&
Original file line number Diff line number Diff line change 1+ export function stripFileExtension ( fileName : string ) : string {
2+ const trimmedName = fileName . trim ( ) ;
3+ const extensionStart = trimmedName . lastIndexOf ( '.' ) ;
4+
5+ if ( extensionStart <= 0 ) {
6+ return trimmedName ;
7+ }
8+
9+ return trimmedName . slice ( 0 , extensionStart ) || trimmedName ;
10+ }
You can’t perform that action at this time.
0 commit comments