1
0

Fix h1-h4 regression

This commit is contained in:
Zef Hemel 2024-01-22 16:25:55 +01:00
parent c1c54c07cf
commit 3eec0758e7
6 changed files with 10 additions and 6 deletions

View File

@ -107,10 +107,12 @@ export async function insertSnippetTemplate(slashCompletion: SlashCompletion) {
cursorPos = await editor.getCursor();
if (snippetTemplate.matchRegex) {
if (snippetTemplate.match || snippetTemplate.matchRegex) {
const pageText = await editor.getText();
// Regex matching mode
const matchRegex = new RegExp(snippetTemplate.matchRegex);
const matchRegex = new RegExp(
(snippetTemplate.match || snippetTemplate.matchRegex)!,
);
let startOfLine = cursorPos;
while (startOfLine > 0 && pageText[startOfLine - 1] !== "\n") {

View File

@ -36,6 +36,8 @@ export const SnippetConfig = refineCommand(
slashCommand: z.string(), // trigger
// Regex match to apply (implicitly makes the body the regex replacement)
matchRegex: z.string().optional(),
// Deprecated: use matchRegex instead (for backwards compatibility)
match: z.string().optional(),
insertAt: z.enum([
"cursor",
"line-start",

View File

@ -3,6 +3,6 @@ tags: template
description: Make this a level 1 heading
hooks.snippet:
slashCommand: h1
match: "^#*\\s*"
matchRegex: "^#*\\s*"
---
#

View File

@ -3,6 +3,6 @@ tags: template
description: Make this a level 2 heading
hooks.snippet:
slashCommand: h2
match: "^#*\\s*"
matchRegex: "^#*\\s*"
---
##

View File

@ -3,6 +3,6 @@ tags: template
description: Make this a level 3 heading
hooks.snippet:
slashCommand: h3
match: "^#*\\s*"
matchRegex: "^#*\\s*"
---
###

View File

@ -3,6 +3,6 @@ tags: template
description: Make this a level 4 heading
hooks.snippet:
slashCommand: h4
match: "^#*\\s*"
matchRegex: "^#*\\s*"
---
####