From 042dd3307e300c8ed4a0f376713a9dea4feba05d Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 17 Apr 2022 14:03:07 +0200 Subject: [PATCH] feat(RelationSuggester): :sparkles: Add wikilink brackets after relation selection --- .vscode/settings.json | 3 ++- main.js | 11 ++++++----- src/RelationSuggestor.ts | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) 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 + ); } }