mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 22:25:29 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
325f2384b1 | ||
|
|
e3d6be193a | ||
|
|
f5f9d49b0b | ||
|
|
6579606935 |
@@ -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).
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user