3 Commits
0.8.2 ... 0.8.3

Author SHA1 Message Date
Daniel Bauer
d85c07126f bump version 2024-12-18 11:07:11 +01:00
Daniel Bauer
020054857b feat: remove lookbehinds, make compatible with iOS 2024-12-18 11:07:06 +01:00
Daniel Bauer
f58f736df4 feat: replace innerHTML call with createEL (obsidian plugin guidelines) 2024-12-18 10:34:00 +01:00
6 changed files with 46 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
{ {
"id": "dataview-autocompletion", "id": "dataview-autocompletion",
"name": "Dataview Autocompletion", "name": "Dataview Autocompletion",
"version": "0.8.2", "version": "0.8.3",
"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.8.2", "version": "0.8.3",
"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": {
@@ -8,6 +8,7 @@
"build": "npx rollup --config rollup.config.js --environment BUILD:production", "build": "npx rollup --config rollup.config.js --environment BUILD:production",
"check-format": "npx prettier --check src", "check-format": "npx prettier --check src",
"test": "npx jest", "test": "npx jest",
"bdd": "npx jest -i --watch --no-cache",
"version": "node ersion-bump.mjs && git add manifest.json versions.json" "version": "node ersion-bump.mjs && git add manifest.json versions.json"
}, },
"keywords": [ "keywords": [

View File

@@ -14,6 +14,10 @@ const createBaseConfig = (outdir) => ({
src: "manifest.json", src: "manifest.json",
dest: outdir, dest: outdir,
}, },
{
src: "styles.css",
dest: outdir,
},
], ],
}), }),
), ),

View File

@@ -68,9 +68,19 @@ export class DataviewSuggester extends EditorSuggest<String> {
} }
renderSuggestion(value: string, el: HTMLElement): void { renderSuggestion(value: string, el: HTMLElement): void {
// replace marks with bold // Split the value into parts based on the <mark> tags and their content
const formattedHtml = value.replace(/<mark>(.*?)<\/mark>/g, '<span style="font-weight: bold;">$1</span>'); const parts = value.split(/(<mark>.*?<\/mark>)/g);
el.innerHTML = formattedHtml;
// 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 { selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {

View File

@@ -3,29 +3,28 @@
* and captures the enclosed text * and captures the enclosed text
* If the brackets start a markdown link, they are ignored. * If the brackets start a markdown link, they are ignored.
* Wiki links don't need to be ignored since Obsidian overwrites suggestions for them. * 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( const filledRegex = new RegExp(
"(" + [
[ // pattern for parantheses
// pattern for parantheses // look for opening parantheses; no closing or opening square bracket before to exlude markdown links, etc.
// pos. lookbehind for opening parantheses; no closing square bracket before to exlude markdown links /(?:^\(|[^\[\]]\()/,
/(?<=^\(|[^\]]\()/, /(.+?)/,
/.+?/, // pos. lookahead for closing paranthesis; not followed by another one for nested ((test))
// pos. lookahead for closing paranthesis; not followed by another one for nested ((test)) /(?=\)$|\)[^\)])/,
/(?=\)$|\)[^\)])/,
/|/, /|/,
// pattern for square brackets // 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!) // pos. lookahead for closing bracket; not followed by another one ([[test]]) or an opening paranthese (markdown link!)
/(?=\]$|\][^\]\(])/, /(?=\]$|\][^\]\(])/,
] ]
.map((s) => s.source) .map((s) => s.source)
.join("") + .join(""),
")",
"g", "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 { function getTriggerTextFromRegex(line: string, cursorPos: number, regex: RegExp): [string, number, number] | null {
let matches = Array.from(line.matchAll(regex)); let matches = Array.from(line.matchAll(regex));
console.log(matches);
for (const match of matches) { for (const match of matches) {
if (match.index === undefined) { if (match.index === undefined) {
continue; continue;
} }
const matchStart = match!.index; const matchText = match[1] || match[2];
const matchEnd = matchStart + match[1].length; const matchStart = match!.index + match[0].indexOf(matchText);
const matchEnd = matchStart + matchText.length;
const cursorInMatch = cursorPos >= matchStart && cursorPos <= matchEnd; const cursorInMatch = cursorPos >= matchStart && cursorPos <= matchEnd;
if (cursorInMatch) { if (cursorInMatch) {
return [match[1], matchStart, matchEnd]; return [matchText, matchStart, matchEnd];
} }
} }
return null; return null;

3
styles.css Normal file
View File

@@ -0,0 +1,3 @@
span.suggestion-highlight {
font-weight: bold;
}