@@ -84,10 +84,27 @@ export function activate(context: vscode.ExtensionContext) {
8484 publicFolder : string ,
8585 bookFolder : string ,
8686 addPrefix : boolean = false ,
87+ position ?: vscode . Position ,
88+ linePrefix ?: string ,
8789 ) : vscode . CompletionItem [ ] {
8890 const items : vscode . CompletionItem [ ] = [ ] ;
8991 const currentDir = path . dirname ( currentDocPath ) ;
9092
93+ // Calculate the range to replace if position and linePrefix are provided
94+ let replaceRange : vscode . Range | undefined ;
95+ if ( position && linePrefix ) {
96+ const srcMatch = linePrefix . match ( / (?: s r c | t h u m b n a i l | p o s t e r ) = \" ( [ ^ " ] * ) $ / ) ;
97+ if ( srcMatch ) {
98+ const startChar = position . character - srcMatch [ 1 ] . length ;
99+ replaceRange = new vscode . Range (
100+ position . line ,
101+ startChar ,
102+ position . line ,
103+ position . character
104+ ) ;
105+ }
106+ }
107+
91108 files . forEach ( ( f ) => {
92109 const filePath = f . path ;
93110
@@ -101,6 +118,9 @@ export function activate(context: vscode.ExtensionContext) {
101118 item . detail = `Public: /${ publicRel } ` ;
102119 item . insertText = addPrefix ? "/" + publicRel : publicRel ;
103120 item . sortText = "0_" + publicRel ; // Sort public paths first
121+ if ( replaceRange ) {
122+ item . range = replaceRange ;
123+ }
104124 items . push ( item ) ;
105125 }
106126
@@ -114,6 +134,9 @@ export function activate(context: vscode.ExtensionContext) {
114134 item . detail = `Book: /${ bookRel } ` ;
115135 item . insertText = addPrefix ? "/" + bookRel : bookRel ;
116136 item . sortText = "1_" + bookRel ;
137+ if ( replaceRange ) {
138+ item . range = replaceRange ;
139+ }
117140 items . push ( item ) ;
118141 }
119142
@@ -129,6 +152,9 @@ export function activate(context: vscode.ExtensionContext) {
129152 item . detail = `Relative: ${ normalizedRel } ` ;
130153 item . insertText = normalizedRel ;
131154 item . sortText = "2_" + relPath ;
155+ if ( replaceRange ) {
156+ item . range = replaceRange ;
157+ }
132158 items . push ( item ) ;
133159 }
134160 }
@@ -214,7 +240,9 @@ export function activate(context: vscode.ExtensionContext) {
214240 workspaceFolder ,
215241 path . join ( workspaceFolder , "public" ) ,
216242 path . join ( workspaceFolder , "book" ) ,
217- true
243+ true ,
244+ position ,
245+ linePrefix
218246 ) ;
219247 } else {
220248 // Only show absolute paths
@@ -446,7 +474,9 @@ export function activate(context: vscode.ExtensionContext) {
446474 workspaceFolder ,
447475 path . join ( workspaceFolder , "public" ) ,
448476 path . join ( workspaceFolder , "book" ) ,
449- true
477+ true ,
478+ position ,
479+ linePrefix
450480 ) ;
451481 } ,
452482 } ,
@@ -491,7 +521,9 @@ export function activate(context: vscode.ExtensionContext) {
491521 workspaceFolder ,
492522 path . join ( workspaceFolder , "public" ) ,
493523 path . join ( workspaceFolder , "book" ) ,
494- true
524+ true ,
525+ position ,
526+ linePrefix
495527 ) ;
496528 } ,
497529 } ,
@@ -534,7 +566,9 @@ export function activate(context: vscode.ExtensionContext) {
534566 workspaceFolder ,
535567 path . join ( workspaceFolder , "public" ) ,
536568 path . join ( workspaceFolder , "book" ) ,
537- true
569+ true ,
570+ position ,
571+ linePrefix
538572 ) ;
539573 } ,
540574 } ,
0 commit comments