10 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
Daniel Bauer
26227eac6e bump version 2025-01-27 10:04:15 +01:00
Daniel Bauer
ba4dab5dc4 chore: remove logging 2025-01-27 10:03:19 +01:00
daniel
6b008d452a chore: fix formatting 2024-12-27 22:41:14 +01:00
daniel
314f99f462 bump version 2024-12-27 22:39:44 +01:00
daniel
064320bc5b chore: remove logging statements 2024-12-27 22:39:22 +01:00
daniel
5f7fdb244a chore: remove obsidian from name 2024-12-27 22:37:15 +01:00
5 changed files with 40 additions and 16 deletions

View File

@@ -1,8 +1,8 @@
# Obsidian Dataview Autocompletion # Dataview Autocompletion
This is a plugin for Obsidian (https://obsidian.md). This is a plugin for Obsidian (https://obsidian.md).
Obsidian Dataview Autocomplete enhances the functionality of the popular [Dataview plugin](https://github.com/blacksmithgu/obsidian-dataview) Dataview Autocomplete enhances the functionality of the popular [Dataview plugin](https://github.com/blacksmithgu/obsidian-dataview)
by providing autocomplete suggestions for metadata fields in the editor. This makes it easy to reuse existing fields and reduces typing errors. by providing autocomplete suggestions for metadata fields in the editor. This makes it easy to reuse existing fields and reduces typing errors.
<img src="./assets/demo.gif" alt="Demo" width="400" > <img src="./assets/demo.gif" alt="Demo" width="400" >
@@ -14,7 +14,9 @@ by providing autocomplete suggestions for metadata fields in the editor. This ma
## Installation ## 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. 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). 2. Create a folder named "dataview-autocompletion" in the Obsidian plugins folder (.obsidian/plugins).

View File

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

View File

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

View File

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

View File

@@ -14,8 +14,8 @@ export class SuggestionIndex {
} }
public buildNewIndex() { public buildNewIndex() {
console.log("Begin Rebuilding dataview suggestion index"); // console.log("Begin Rebuilding dataview suggestion index");
const startTime = performance.now(); // const startTime = performance.now();
const dataviewApi = getAPI(this.plugin.app); const dataviewApi = getAPI(this.plugin.app);
const newSuggestions: string[] = []; const newSuggestions: string[] = [];
@@ -54,10 +54,10 @@ export class SuggestionIndex {
this.suggestionsRefCount = newSuggestionsRefCount; this.suggestionsRefCount = newSuggestionsRefCount;
this.suggestionsRefs = newSuggestionsRefs; this.suggestionsRefs = newSuggestionsRefs;
const endTime = performance.now(); // const endTime = performance.now();
console.log( // console.log(
`Rebuilt dataview autocomplete index (${this.suggestionsList.length} elements, ${(endTime - startTime).toFixed(2)}ms)`, // `Rebuilt dataview autocomplete index (${this.suggestionsList.length} elements, ${(endTime - startTime).toFixed(2)}ms)`,
); // );
} }
public updateIndex(type: string, file: TFile, oldPath?: string) { public updateIndex(type: string, file: TFile, oldPath?: string) {
@@ -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;
} }