mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-09-11 14:45:30 +00:00
feat: add some trigger tests
This commit is contained in:
17
src/trigger.ts
Normal file
17
src/trigger.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user