parent
5a2acb7773
commit
82c70007a3
|
@ -63,6 +63,14 @@ interface CompletionContext {
|
|||
readonly anchorInfo?: AnchorContext;
|
||||
}
|
||||
|
||||
function tryDecodeUriComponent(str: string): string {
|
||||
try {
|
||||
return decodeURIComponent(str);
|
||||
} catch {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
export class PathCompletionProvider implements vscode.CompletionItemProvider {
|
||||
|
||||
public static register(selector: vscode.DocumentSelector, engine: MarkdownEngine): vscode.Disposable {
|
||||
|
@ -157,7 +165,7 @@ export class PathCompletionProvider implements vscode.CompletionItemProvider {
|
|||
const suffix = lineSuffixText.match(/^[^\)\s]*/);
|
||||
return {
|
||||
kind: CompletionContextKind.Link,
|
||||
linkPrefix: prefix,
|
||||
linkPrefix: tryDecodeUriComponent(prefix),
|
||||
linkTextStartPosition: position.translate({ characterDelta: -prefix.length }),
|
||||
linkSuffix: suffix ? suffix[0] : '',
|
||||
anchorInfo: this.getAnchorContext(prefix),
|
||||
|
@ -174,7 +182,7 @@ export class PathCompletionProvider implements vscode.CompletionItemProvider {
|
|||
const suffix = lineSuffixText.match(/^[^\s]*/);
|
||||
return {
|
||||
kind: CompletionContextKind.LinkDefinition,
|
||||
linkPrefix: prefix,
|
||||
linkPrefix: tryDecodeUriComponent(prefix),
|
||||
linkTextStartPosition: position.translate({ characterDelta: -prefix.length }),
|
||||
linkSuffix: suffix ? suffix[0] : '',
|
||||
anchorInfo: this.getAnchorContext(prefix),
|
||||
|
|
|
@ -151,4 +151,20 @@ suite('Markdown path completion provider', () => {
|
|||
|
||||
assert.ok(completions.some(x => x.insertText === 'file%20with%20space.md'), 'Has encoded path completion');
|
||||
});
|
||||
|
||||
test('Should complete paths for path with encoded spaces', async () => {
|
||||
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
|
||||
`[](./sub%20with%20space/${CURSOR})`
|
||||
));
|
||||
|
||||
assert.ok(completions.some(x => x.insertText === 'file.md'), 'Has file from space');
|
||||
});
|
||||
|
||||
test('Should complete definition path for path with encoded spaces', async () => {
|
||||
const completions = await getCompletionsAtCursor(workspaceFile('new.md'), joinLines(
|
||||
`[def]: ./sub%20with%20space/${CURSOR}`
|
||||
));
|
||||
|
||||
assert.ok(completions.some(x => x.insertText === 'file.md'), 'Has file from space');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# header
|
Loading…
Reference in New Issue