Use un-encoded file paths are rename placeholder

This commit is contained in:
Matt Bierner 2022-04-20 18:16:07 -07:00
parent 7b1168660a
commit 59b6227bf3
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 19 additions and 1 deletions

View file

@ -37,6 +37,14 @@ export interface MdWorkspaceEdit {
readonly fileRenames?: ReadonlyArray<MdFileRenameEdit>;
}
function tryDecodeUri(str: string): string {
try {
return decodeURI(str);
} catch {
return str;
}
}
export class MdRenameProvider extends Disposable implements vscode.RenameProvider {
private cachedRefs?: {
@ -98,7 +106,7 @@ export class MdRenameProvider extends Disposable implements vscode.RenameProvide
if (!range) {
throw new Error(this.renameNotSupportedText);
}
return { range, placeholder: document.getText(range) };
return { range, placeholder: tryDecodeUri(document.getText(range)) };
}
}
}

View file

@ -412,6 +412,16 @@ suite('markdown: rename', () => {
});
});
test('Path rename should use un-encoded paths as placeholder', async () => {
const uri = workspacePath('sub', 'doc with spaces.md');
const doc = new InMemoryDocument(uri, joinLines(
`[text](/sub/doc%20with%20spaces.md)`,
));
const info = await prepareRename(doc, new vscode.Position(0, 10), new InMemoryWorkspaceMarkdownDocuments([doc]));
assert.strictEqual(info!.placeholder, '/sub/doc with spaces.md');
});
test('Path rename should encode paths', async () => {
const uri = workspacePath('sub', 'doc.md');
const doc = new InMemoryDocument(uri, joinLines(