diff --git a/.vscode/settings.json b/.vscode/settings.json index d56c8a04..0c5b8a26 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,6 +28,7 @@ "impliedRelations", "DataviewNotes", "DateNotes", - "API" + "API", + "RelationSuggester" ] } \ No newline at end of file diff --git a/main.js b/main.js index 46673eb3..dfbd7a05 100644 --- a/main.js +++ b/main.js @@ -37708,11 +37708,12 @@ class RelationSuggestor extends obsidian.EditorSuggest { } selectSuggestion(suggestion) { const { context, plugin } = this; - if (context) { - const trig = plugin.settings.relSuggestorTrigger; - const { start, end, editor } = context; - editor.replaceRange(suggestion + (isInsideYaml(plugin.app) ? ": " : ":: "), { ch: start.ch + 1 - trig.length, line: start.line }, end); - } + if (!context) + return; + const trig = plugin.settings.relSuggestorTrigger; + const { start, end, editor } = context; + const replacement = suggestion + (isInsideYaml(plugin.app) ? ": " : ":: ") + '[['; + editor.replaceRange(replacement, { ch: start.ch + 1 - trig.length, line: start.line }, end); } } diff --git a/src/RelationSuggestor.ts b/src/RelationSuggestor.ts index 4514e864..faa231e4 100644 --- a/src/RelationSuggestor.ts +++ b/src/RelationSuggestor.ts @@ -56,15 +56,16 @@ export class RelationSuggestor extends EditorSuggest { selectSuggestion(suggestion: string): void { const { context, plugin } = this; - if (context) { - const trig = plugin.settings.relSuggestorTrigger; - const { start, end, editor } = context; + if (!context) return - editor.replaceRange( - suggestion + (isInsideYaml(plugin.app) ? ": " : ":: "), - { ch: start.ch + 1 - trig.length, line: start.line }, - end - ); - } + const trig = plugin.settings.relSuggestorTrigger; + const { start, end, editor } = context; + + const replacement = suggestion + (isInsideYaml(plugin.app) ? ": " : ":: ") + '[['; + editor.replaceRange( + replacement, + { ch: start.ch + 1 - trig.length, line: start.line }, + end + ); } }