mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-11 14:45:30 +00:00
17 lines
524 B
TypeScript
17 lines
524 B
TypeScript
const triggerRegex = /\((.*?)\)/g
|
|
|
|
export function getTriggerText(line: string, cursorPos: number): [string, number, number] | null {
|
|
triggerRegex.lastIndex = 0 // resetting global regex
|
|
|
|
let match = null
|
|
while ((match = triggerRegex.exec(line)) !== null) {
|
|
const cursorInMatch = cursorPos > match.index && cursorPos <= match.index + match[1].length + 1
|
|
|
|
if (cursorInMatch) {
|
|
return [match[1], match.index+1, match.index + match[1].length + 1]
|
|
}
|
|
|
|
}
|
|
return null
|
|
|
|
} |