Fix frontmatter line map (#209556)

Fixes #209267
This commit is contained in:
Matt Bierner
2024-04-04 10:39:21 -07:00
committed by GitHub
parent 125e308ea4
commit 7a623b31fb
3 changed files with 37 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import { InsertMarkdownLink, findValidUriInText, shouldInsertMarkdownLinkByDefau
import { noopToken } from '../util/cancellation';
import { UriList } from '../util/uriList';
import { createNewMarkdownEngine } from './engine';
import { joinLines } from './util';
function makeTestDoc(contents: string) {
return new InMemoryDocument(vscode.Uri.file('test.md'), contents);
@@ -307,5 +308,36 @@ suite('createEditAddingLinksForUriList', () => {
await shouldInsertMarkdownLinkByDefault(createNewMarkdownEngine(), makeTestDoc('<>'), InsertMarkdownLink.Smart, [new vscode.Range(0, 1, 0, 1)], noopToken),
false);
});
test('Smart should be disabled in frontmatter', async () => {
const textDoc = makeTestDoc(joinLines(
`---`,
`layout: post`,
`title: Blogging Like a Hacker`,
`---`,
``,
`Link Text`
));
assert.strictEqual(
await shouldInsertMarkdownLinkByDefault(createNewMarkdownEngine(), textDoc, InsertMarkdownLink.Smart, [new vscode.Range(0, 0, 0, 0)], noopToken),
false);
assert.strictEqual(
await shouldInsertMarkdownLinkByDefault(createNewMarkdownEngine(), textDoc, InsertMarkdownLink.Smart, [new vscode.Range(1, 0, 1, 0)], noopToken),
false);
});
test('Smart should enabled after frontmatter', async () => {
assert.strictEqual(
await shouldInsertMarkdownLinkByDefault(createNewMarkdownEngine(), makeTestDoc(joinLines(
`---`,
`layout: post`,
`title: Blogging Like a Hacker`,
`---`,
``,
`Link Text`
)), InsertMarkdownLink.Smart, [new vscode.Range(5, 0, 5, 0)], noopToken),
true);
});
});
});