@@ -2,6 +2,7 @@ import { postCategoryDataProvider } from '@/tree-view/provider/post-category-tre
2
2
import { postDataProvider } from '@/tree-view/provider/post-data-provider'
3
3
import { LocalState } from '@/ctx/local-state'
4
4
import { Uri } from 'vscode'
5
+ import { WorkspaceCfg } from '@/ctx/cfg/workspace'
5
6
6
7
const validatePostFileMap = ( map : PostFileMap ) => map [ 0 ] >= 0 && map [ 1 ] !== ''
7
8
export type PostFileMap = [ postId : number , filePath : string ]
@@ -11,6 +12,10 @@ function getMaps(): PostFileMap[] {
11
12
return < PostFileMap [ ] > LocalState . getState ( storageKey ) ?? [ ]
12
13
}
13
14
15
+ function isUriPath ( path : string ) {
16
+ return path . startsWith ( '/' )
17
+ }
18
+
14
19
export namespace PostFileMapManager {
15
20
export async function updateOrCreateMany (
16
21
arg :
@@ -67,7 +72,7 @@ export namespace PostFileMapManager {
67
72
if ( map === undefined ) return
68
73
const path = map [ 1 ]
69
74
if ( path === '' ) return
70
- return path . startsWith ( '/' ) ? Uri . parse ( path ) . fsPath : path
75
+ return isUriPath ( path ) ? Uri . parse ( path ) . fsPath : path
71
76
}
72
77
73
78
export function getPostId ( filePath : string ) : number | undefined {
@@ -81,4 +86,16 @@ export namespace PostFileMapManager {
81
86
if ( match == null ) return
82
87
return Number ( match [ 1 ] )
83
88
}
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
+ }
84
101
}
0 commit comments