shortcut-logger.ts 592 B

1234567891011121314151617181920
  1. import { ViewPlugin } from '@codemirror/view'
  2. import { emitShortcutEvent } from './toolbar/utils/analytics'
  3. import { runShortcut } from '../languages/latex/shortcuts'
  4. /**
  5. * A custom view plugin that watches for transactions with the `runShortcut` annotation,
  6. * and logs the shortcut name for analytics.
  7. */
  8. export const shortcutLogger = ViewPlugin.define(view => {
  9. return {
  10. update(update) {
  11. for (const tr of update.transactions) {
  12. const action = tr.annotation(runShortcut)
  13. if (action) {
  14. emitShortcutEvent(view, action)
  15. }
  16. }
  17. },
  18. }
  19. })