mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-10 22:25:29 +00:00
feat: remove lookbehinds, make compatible with iOS
This commit is contained in:
@@ -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": [
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user