mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 10:32:19 -05:00
cce1a91205
Fix regular expression for completion event logging GitOrigin-RevId: fbe3b91722fe40d4bb1116f23a78ebcebbd02b37
28 lines
900 B
TypeScript
28 lines
900 B
TypeScript
import { ViewPlugin } from '@codemirror/view'
|
|
import { pickedCompletion } from '@codemirror/autocomplete'
|
|
import { emitCompletionEvent } from './toolbar/utils/analytics'
|
|
|
|
/**
|
|
* A custom view plugin that watches for transactions with the `pickedCompletion` annotation.
|
|
* If the completion label starts with a command, log that command for analytics.
|
|
*/
|
|
export const completionLogger = ViewPlugin.define(view => {
|
|
return {
|
|
update(update) {
|
|
for (const tr of update.transactions) {
|
|
const completion = tr.annotation(pickedCompletion)
|
|
if (completion) {
|
|
const command = completionCommand(completion.label)
|
|
if (command) {
|
|
emitCompletionEvent(view, command)
|
|
}
|
|
}
|
|
}
|
|
},
|
|
}
|
|
})
|
|
|
|
const completionCommand = (label: string): string | null => {
|
|
const matches = label.match(/^\\(\w+)/)
|
|
return matches ? matches[1] : null
|
|
}
|