Skip to content

Commit

Permalink
feat(RelationSuggester): ✨ Add wikilink brackets after relation selec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
SkepticMystic committed Apr 17, 2022
1 parent c6983c6 commit 042dd33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"impliedRelations",
"DataviewNotes",
"DateNotes",
"API"
"API",
"RelationSuggester"
]
}
11 changes: 6 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/RelationSuggestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ export class RelationSuggestor extends EditorSuggest<string> {

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
);
}
}

0 comments on commit 042dd33

Please sign in to comment.