Files
obsidian-dataview-autocompl…/src/trigger.ts
2024-12-11 00:36:43 +01:00

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
}