mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 22:25:29 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d85c07126f | ||
|
|
020054857b | ||
|
|
f58f736df4 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "dataview-autocompletion",
|
||||
"name": "Dataview Autocompletion",
|
||||
"version": "0.8.2",
|
||||
"version": "0.8.3",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Adds autocompletion to Dataview metadata fields",
|
||||
"author": "Daniel Bauer",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-dataview-autocompletion",
|
||||
"version": "0.8.2",
|
||||
"version": "0.8.3",
|
||||
"description": "This is a plugin for Obsidian that provides autocompletion for Dataview metadata fields",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
@@ -8,6 +8,7 @@
|
||||
"build": "npx rollup --config rollup.config.js --environment BUILD:production",
|
||||
"check-format": "npx prettier --check src",
|
||||
"test": "npx jest",
|
||||
"bdd": "npx jest -i --watch --no-cache",
|
||||
"version": "node ersion-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [
|
||||
|
||||
@@ -14,6 +14,10 @@ const createBaseConfig = (outdir) => ({
|
||||
src: "manifest.json",
|
||||
dest: outdir,
|
||||
},
|
||||
{
|
||||
src: "styles.css",
|
||||
dest: outdir,
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -68,9 +68,19 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
||||
}
|
||||
|
||||
renderSuggestion(value: string, el: HTMLElement): void {
|
||||
// replace marks with bold
|
||||
const formattedHtml = value.replace(/<mark>(.*?)<\/mark>/g, '<span style="font-weight: bold;">$1</span>');
|
||||
el.innerHTML = formattedHtml;
|
||||
// Split the value into parts based on the <mark> tags and their content
|
||||
const parts = value.split(/(<mark>.*?<\/mark>)/g);
|
||||
|
||||
// We cannot use inner HTML; Create a span for each part
|
||||
parts.forEach((part) => {
|
||||
if (part.startsWith("<mark>") && part.endsWith("</mark>")) {
|
||||
const text = part.slice(6, -7); // Remove <mark> and </mark>
|
||||
el.createEl("span", { text, cls: "suggestion-highlight" });
|
||||
} else {
|
||||
// For normal text, create a text node or <span>
|
||||
el.createEl("span", { text: part });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {
|
||||
|
||||
@@ -3,29 +3,28 @@
|
||||
* and captures the enclosed text
|
||||
* If the brackets start a markdown link, they are ignored.
|
||||
* Wiki links don't need to be ignored since Obsidian overwrites suggestions for them.
|
||||
* We are not allowd to use lookbehinds, because iOS does not support them in older versions.
|
||||
*/
|
||||
const filledRegex = new RegExp(
|
||||
"(" +
|
||||
[
|
||||
// pattern for parantheses
|
||||
// pos. lookbehind for opening parantheses; no closing square bracket before to exlude markdown links
|
||||
/(?<=^\(|[^\]]\()/,
|
||||
/.+?/,
|
||||
// look for opening parantheses; no closing or opening square bracket before to exlude markdown links, etc.
|
||||
/(?:^\(|[^\[\]]\()/,
|
||||
/(.+?)/,
|
||||
// pos. lookahead for closing paranthesis; not followed by another one for nested ((test))
|
||||
/(?=\)$|\)[^\)])/,
|
||||
|
||||
/|/,
|
||||
|
||||
// pattern for square brackets
|
||||
// pos. lookbehind for opening square bracket
|
||||
/(?<=\[)/,
|
||||
/.+?/,
|
||||
// look for opening square brackets
|
||||
/(?:\[)/,
|
||||
/(.+?)/,
|
||||
// pos. lookahead for closing bracket; not followed by another one ([[test]]) or an opening paranthese (markdown link!)
|
||||
/(?=\]$|\][^\]\(])/,
|
||||
]
|
||||
.map((s) => s.source)
|
||||
.join("") +
|
||||
")",
|
||||
.join(""),
|
||||
"g",
|
||||
);
|
||||
|
||||
@@ -52,17 +51,19 @@ export function getTriggerText(line: string, cursorPos: number): [string, number
|
||||
*/
|
||||
function getTriggerTextFromRegex(line: string, cursorPos: number, regex: RegExp): [string, number, number] | null {
|
||||
let matches = Array.from(line.matchAll(regex));
|
||||
console.log(matches);
|
||||
for (const match of matches) {
|
||||
if (match.index === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const matchStart = match!.index;
|
||||
const matchEnd = matchStart + match[1].length;
|
||||
const matchText = match[1] || match[2];
|
||||
const matchStart = match!.index + match[0].indexOf(matchText);
|
||||
const matchEnd = matchStart + matchText.length;
|
||||
const cursorInMatch = cursorPos >= matchStart && cursorPos <= matchEnd;
|
||||
|
||||
if (cursorInMatch) {
|
||||
return [match[1], matchStart, matchEnd];
|
||||
return [matchText, matchStart, matchEnd];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
3
styles.css
Normal file
3
styles.css
Normal file
@@ -0,0 +1,3 @@
|
||||
span.suggestion-highlight {
|
||||
font-weight: bold;
|
||||
}
|
||||
Reference in New Issue
Block a user