mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Try automatically adding .md file extension to new paths on rename
This commit is contained in:
parent
0ac39e800d
commit
0610f195fb
|
@ -10,6 +10,7 @@ import { resolveDocumentLink } from '../util/openDocumentLink';
|
|||
import { MdWorkspaceContents, SkinnyTextDocument } from '../workspaceContents';
|
||||
import { InternalHref } from './documentLinkProvider';
|
||||
import { MdHeaderReference, MdLinkReference, MdReference, MdReferencesProvider, tryFindMdDocumentForLink } from './references';
|
||||
import * as URI from 'vscode-uri';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
@ -145,7 +146,17 @@ export class MdRenameProvider extends Disposable implements vscode.RenameProvide
|
|||
|
||||
const targetDoc = await tryFindMdDocumentForLink(triggerHref, this.workspaceContents);
|
||||
const targetUri = targetDoc?.uri ?? triggerHref.path;
|
||||
const newFilePath = resolveDocumentLink(newName, triggerHref.path);
|
||||
|
||||
let newFilePath = resolveDocumentLink(newName, triggerHref.path);
|
||||
if (!URI.Utils.extname(newFilePath)) {
|
||||
// If the newly entered path doesn't have a file extension but the original file did
|
||||
// tack on a .md file extension
|
||||
if (URI.Utils.extname(targetUri)) {
|
||||
newFilePath = newFilePath.with({
|
||||
path: newFilePath.path + '.md'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// First rename the file
|
||||
fileRenames.push({ from: targetUri.toString(), to: newFilePath.toString() });
|
||||
|
|
|
@ -463,6 +463,25 @@ suite('markdown: rename', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('Path rename should use .md extension on extension-less link', async () => {
|
||||
const uri = workspacePath('doc.md');
|
||||
const doc = new InMemoryDocument(uri, joinLines(
|
||||
`[text](/doc#header)`,
|
||||
`[ref]: /doc#other`,
|
||||
));
|
||||
|
||||
const edit = await getRenameEdits(doc, new vscode.Position(0, 10), '/new File', new InMemoryWorkspaceMarkdownDocuments([doc]));
|
||||
assertEditsEqual(edit!, {
|
||||
originalUri: uri,
|
||||
newUri: workspacePath('new File.md'),
|
||||
}, {
|
||||
uri: uri, edits: [
|
||||
new vscode.TextEdit(new vscode.Range(0, 7, 0, 11), '/new%20File'),
|
||||
new vscode.TextEdit(new vscode.Range(1, 7, 1, 11), '/new%20File'),
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
test('Rename on link should use header text as placeholder', async () => {
|
||||
const uri = workspacePath('doc.md');
|
||||
const doc = new InMemoryDocument(uri, joinLines(
|
||||
|
|
Loading…
Reference in a new issue