@@ -145,17 +145,22 @@ function createThrottledValue(getValue: () => string) {
145145 return value
146146}
147147
148- function relativizeProjectPaths ( text : string , directory ?: string ) {
149- if ( ! text ) return ""
150- if ( ! directory ) return text
151- if ( directory === "/" ) return text
152- if ( directory === "\\" ) return text
153- return text . split ( directory ) . join ( "" )
148+ function relativizeProjectPath ( path : string , directory ?: string ) {
149+ if ( ! path ) return ""
150+ if ( ! directory ) return path
151+ if ( directory === "/" ) return path
152+ if ( directory === "\\" ) return path
153+ if ( path === directory ) return ""
154+
155+ const separator = directory . includes ( "\\" ) ? "\\" : "/"
156+ const prefix = directory . endsWith ( separator ) ? directory : directory + separator
157+ if ( ! path . startsWith ( prefix ) ) return path
158+ return path . slice ( directory . length )
154159}
155160
156161function getDirectory ( path : string | undefined ) {
157162 const data = useData ( )
158- return relativizeProjectPaths ( _getDirectory ( path ) , data . directory )
163+ return relativizeProjectPath ( _getDirectory ( path ) , data . directory )
159164}
160165
161166import type { IconProps } from "./icon"
@@ -1066,7 +1071,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
10661071 return items . filter ( ( x ) => ! ! x ) . join ( " \u00B7 " )
10671072 } )
10681073
1069- const displayText = ( ) => relativizeProjectPaths ( ( part . text ?? "" ) . trim ( ) , data . directory )
1074+ const displayText = ( ) => ( part . text ?? "" ) . trim ( )
10701075 const throttledText = createThrottledValue ( displayText )
10711076 const isLastTextPart = createMemo ( ( ) => {
10721077 const last = ( data . store . part ?. [ props . message . id ] ?? [ ] )
@@ -1168,7 +1173,7 @@ ToolRegistry.register({
11681173 < div data-component = "tool-loaded-file" >
11691174 < Icon name = "enter" size = "small" />
11701175 < span >
1171- { i18n . t ( "ui.tool.loaded" ) } { relativizeProjectPaths ( filepath , data . directory ) }
1176+ { i18n . t ( "ui.tool.loaded" ) } { relativizeProjectPath ( filepath , data . directory ) }
11721177 </ span >
11731178 </ div >
11741179 ) }
0 commit comments