4 Commits

Author SHA1 Message Date
Daniel Bauer
325f2384b1 bump version 2025-02-15 11:27:41 +01:00
Daniel Bauer
e3d6be193a feat: add option for prefix suggestion 2025-02-15 11:26:03 +01:00
Daniel Bauer
f5f9d49b0b chore: remove unused timing 2025-02-15 09:53:55 +01:00
Daniel Bauer
6579606935 Update README.md 2025-02-13 09:31:48 +01:00
5 changed files with 34 additions and 10 deletions

View File

@@ -14,7 +14,9 @@ by providing autocomplete suggestions for metadata fields in the editor. This ma
## Installation
While plugin is [waiting](https://github.com/obsidianmd/obsidian-releases/pull/4913) to be reviewed and added to the community plugin list, you can install it manually following the steps below:
The plugin is available through Obsidian as a community plugin.
### Manual installation
1. Download the latest release files (manifest.json, styles.css, main.js) from the Releases page.
2. Create a folder named "dataview-autocompletion" in the Obsidian plugins folder (.obsidian/plugins).

View File

@@ -1,7 +1,7 @@
{
"id": "dataview-autocompletion",
"name": "Dataview Autocompletion",
"version": "0.9.4",
"version": "0.9.5",
"minAppVersion": "0.15.0",
"description": "Adds autocompletion to Dataview metadata fields",
"author": "Daniel Bauer",

View File

@@ -1,6 +1,6 @@
{
"name": "obsidian-dataview-autocompletion",
"version": "0.9.4",
"version": "0.9.5",
"description": "This is a plugin for Obsidian that provides autocompletion for Dataview metadata fields",
"main": "main.js",
"scripts": {

View File

@@ -86,9 +86,17 @@ export class DataviewSuggester extends EditorSuggest<String> {
suggestionText += value.replace(/<mark>(.*?)<\/mark>/g, "$1");
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(
this.app,
htmlToMarkdown(suggestionText),
markdownText,
el,
this.context!.file.path,
this.app.workspace.getActiveViewOfType(MarkdownView)!,
@@ -128,10 +136,20 @@ export class DataviewSuggester extends EditorSuggest<String> {
const { editor, start, end } = this.context!;
editor.replaceRange(value, start, end);
const newCursorPos = {
line: end.line,
ch: start.ch + value.length + 1,
};
// 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,
ch: start.ch + value.length + 1,
};
}
editor.setCursor(newCursorPos);
}

View File

@@ -15,7 +15,7 @@ export class SuggestionIndex {
public buildNewIndex() {
// console.log("Begin Rebuilding dataview suggestion index");
const startTime = performance.now();
// const startTime = performance.now();
const dataviewApi = getAPI(this.plugin.app);
const newSuggestions: string[] = [];
@@ -54,7 +54,7 @@ export class SuggestionIndex {
this.suggestionsRefCount = newSuggestionsRefCount;
this.suggestionsRefs = newSuggestionsRefs;
const endTime = performance.now();
// const endTime = performance.now();
// console.log(
// `Rebuilt dataview autocomplete index (${this.suggestionsList.length} elements, ${(endTime - startTime).toFixed(2)}ms)`,
// );
@@ -159,6 +159,10 @@ export class SuggestionIndex {
let compositeValue = this.formatCompositeValue(key, value);
compositeValues.push(compositeValue);
let prefixValue = key + ":: ";
if (compositeValues.indexOf(prefixValue) < 0) {
compositeValues.push(prefixValue);
}
if (!this.filterCompositeValue(compositeValue)) {
continue;
}