mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 14:15:29 +00:00
feat: add option for prefix suggestion
This commit is contained in:
@@ -86,9 +86,17 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
suggestionText += value.replace(/<mark>(.*?)<\/mark>/g, "$1");
|
suggestionText += value.replace(/<mark>(.*?)<\/mark>/g, "$1");
|
||||||
suggestionText += suggestionText.startsWith("(") ? ")" : "]";
|
suggestionText += suggestionText.startsWith("(") ? ")" : "]";
|
||||||
|
|
||||||
|
// Different rendering for prefix suggestions
|
||||||
|
var markdownText;
|
||||||
|
if (/.*\:: [\]\)]/.test(suggestionText)) {
|
||||||
|
markdownText = htmlToMarkdown("[" + suggestionText.slice(1, -1) + "*…*]");
|
||||||
|
} else {
|
||||||
|
markdownText = htmlToMarkdown(suggestionText);
|
||||||
|
}
|
||||||
|
console.log(markdownText);
|
||||||
MarkdownRenderer.render(
|
MarkdownRenderer.render(
|
||||||
this.app,
|
this.app,
|
||||||
htmlToMarkdown(suggestionText),
|
markdownText,
|
||||||
el,
|
el,
|
||||||
this.context!.file.path,
|
this.context!.file.path,
|
||||||
this.app.workspace.getActiveViewOfType(MarkdownView)!,
|
this.app.workspace.getActiveViewOfType(MarkdownView)!,
|
||||||
@@ -128,10 +136,20 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||||||
const { editor, start, end } = this.context!;
|
const { editor, start, end } = this.context!;
|
||||||
editor.replaceRange(value, start, end);
|
editor.replaceRange(value, start, end);
|
||||||
|
|
||||||
const newCursorPos = {
|
// move cursor to end of suggestion for finished suggestions
|
||||||
|
// or to the end of the prefix
|
||||||
|
var newCursorPos;
|
||||||
|
if (value.endsWith(":: ")) {
|
||||||
|
newCursorPos = {
|
||||||
|
line: end.line,
|
||||||
|
ch: start.ch + value.length,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
newCursorPos = {
|
||||||
line: end.line,
|
line: end.line,
|
||||||
ch: start.ch + value.length + 1,
|
ch: start.ch + value.length + 1,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
editor.setCursor(newCursorPos);
|
editor.setCursor(newCursorPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ export class SuggestionIndex {
|
|||||||
|
|
||||||
let compositeValue = this.formatCompositeValue(key, value);
|
let compositeValue = this.formatCompositeValue(key, value);
|
||||||
compositeValues.push(compositeValue);
|
compositeValues.push(compositeValue);
|
||||||
|
let prefixValue = key + ":: ";
|
||||||
|
if (compositeValues.indexOf(prefixValue) < 0) {
|
||||||
|
compositeValues.push(prefixValue);
|
||||||
|
}
|
||||||
if (!this.filterCompositeValue(compositeValue)) {
|
if (!this.filterCompositeValue(compositeValue)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user