@@ -2,6 +2,7 @@ import { postCategoryDataProvider } from '@/tree-view/provider/post-category-tre
22import { postDataProvider } from '@/tree-view/provider/post-data-provider'
33import { LocalState } from '@/ctx/local-state'
44import { Uri } from 'vscode'
5+ import { WorkspaceCfg } from '@/ctx/cfg/workspace'
56
67const validatePostFileMap = ( map : PostFileMap ) => map [ 0 ] >= 0 && map [ 1 ] !== ''
78export type PostFileMap = [ postId : number , filePath : string ]
@@ -11,6 +12,10 @@ function getMaps(): PostFileMap[] {
1112 return < PostFileMap [ ] > LocalState . getState ( storageKey ) ?? [ ]
1213}
1314
15+ function isUriPath ( path : string ) {
16+ return path . startsWith ( '/' )
17+ }
18+
1419export namespace PostFileMapManager {
1520 export async function updateOrCreateMany (
1621 arg :
@@ -67,7 +72,7 @@ export namespace PostFileMapManager {
6772 if ( map === undefined ) return
6873 const path = map [ 1 ]
6974 if ( path === '' ) return
70- return path . startsWith ( '/' ) ? Uri . parse ( path ) . fsPath : path
75+ return isUriPath ( path ) ? Uri . parse ( path ) . fsPath : path
7176 }
7277
7378 export function getPostId ( filePath : string ) : number | undefined {
@@ -81,4 +86,16 @@ export namespace PostFileMapManager {
8186 if ( match == null ) return
8287 return Number ( match [ 1 ] )
8388 }
89+
90+ export function updateWithWorkspace ( oldWorkspaceUri : Uri ) {
91+ const newWorkspaceUri = WorkspaceCfg . getWorkspaceUri ( )
92+ if ( newWorkspaceUri . path === oldWorkspaceUri . path ) return
93+ getMaps ( ) . forEach ( x => {
94+ const filePath = x [ 1 ]
95+ if ( isUriPath ( filePath ) && filePath . indexOf ( oldWorkspaceUri . path ) >= 0 )
96+ x [ 1 ] = filePath . replace ( oldWorkspaceUri . path , newWorkspaceUri . path )
97+ else if ( ! isUriPath ( filePath ) && filePath . indexOf ( oldWorkspaceUri . fsPath ) >= 0 )
98+ x [ 1 ] = filePath . replace ( oldWorkspaceUri . fsPath , newWorkspaceUri . fsPath )
99+ } )
100+ }
84101}
0 commit comments