Remove completion and shortcut event logging (#15633)

GitOrigin-RevId: 35eedb7b18200badef8226eecc58b3c35344f256
This commit is contained in:
Alf Eaton 2023-11-07 11:49:50 +00:00 committed by Copybot
parent 8abf8ba956
commit 54c55360c4
6 changed files with 6 additions and 76 deletions

View file

@ -1,10 +1,5 @@
import { EditorView } from '@codemirror/view' import { EditorView } from '@codemirror/view'
import { import { EditorSelection, EditorState, SelectionRange } from '@codemirror/state'
EditorSelection,
EditorState,
SelectionRange,
TransactionSpec,
} from '@codemirror/state'
import { import {
ensureSyntaxTree, ensureSyntaxTree,
foldedRanges, foldedRanges,
@ -413,10 +408,7 @@ function bubbleUpRange(
return range return range
} }
export function toggleRanges( export function toggleRanges(command: string) {
command: string,
annotations?: TransactionSpec['annotations']
) {
/* There are a number of situations we need to handle in this function. /* There are a number of situations we need to handle in this function.
* In the following examples, the selection range is marked within <> * In the following examples, the selection range is marked within <>
@ -761,7 +753,7 @@ export function toggleRanges(
// Shouldn't happen, but default to just wrapping the content // Shouldn't happen, but default to just wrapping the content
return wrapRangeInCommand(view.state, range, command) return wrapRangeInCommand(view.state, range, command)
}), }),
{ scrollIntoView: true, annotations } { scrollIntoView: true }
) )
return true return true
} }

View file

@ -1,28 +0,0 @@
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
}

View file

@ -47,8 +47,6 @@ import { effectListeners } from './effect-listeners'
import { highlightSpecialChars } from './highlight-special-chars' import { highlightSpecialChars } from './highlight-special-chars'
import { toolbarPanel } from './toolbar/toolbar-panel' import { toolbarPanel } from './toolbar/toolbar-panel'
import { geometryChangeEvent } from './geometry-change-event' import { geometryChangeEvent } from './geometry-change-event'
import { completionLogger } from './completion-logger'
import { shortcutLogger } from './shortcut-logger'
const moduleExtensions: Array<() => Extension> = importOverleafModules( const moduleExtensions: Array<() => Extension> = importOverleafModules(
'sourceEditorExtensions' 'sourceEditorExtensions'
@ -130,8 +128,6 @@ export const createExtensions = (options: Record<string, any>): Extension[] => [
// The built-in extension that highlights the active line in the gutter. // The built-in extension that highlights the active line in the gutter.
highlightActiveLineGutter(), highlightActiveLineGutter(),
inlineBackground(options.visual.visual), inlineBackground(options.visual.visual),
completionLogger,
shortcutLogger,
codemirrorDevTools(), codemirrorDevTools(),
exceptionLogger(), exceptionLogger(),
// CodeMirror extensions provided by modules // CodeMirror extensions provided by modules

View file

@ -1,20 +0,0 @@
import { ViewPlugin } from '@codemirror/view'
import { emitShortcutEvent } from './toolbar/utils/analytics'
import { runShortcut } from '../languages/latex/shortcuts'
/**
* A custom view plugin that watches for transactions with the `runShortcut` annotation,
* and logs the shortcut name for analytics.
*/
export const shortcutLogger = ViewPlugin.define(view => {
return {
update(update) {
for (const tr of update.transactions) {
const action = tr.annotation(runShortcut)
if (action) {
emitShortcutEvent(view, action)
}
}
},
}
})

View file

@ -14,11 +14,3 @@ export function emitCommandEvent(
export function emitToolbarEvent(view: EditorView, command: string) { export function emitToolbarEvent(view: EditorView, command: string) {
emitCommandEvent(view, 'codemirror-toolbar-event', command) emitCommandEvent(view, 'codemirror-toolbar-event', command)
} }
export function emitCompletionEvent(view: EditorView, command: string) {
emitCommandEvent(view, 'codemirror-completion-event', command)
}
export function emitShortcutEvent(view: EditorView, command: string) {
emitCommandEvent(view, 'codemirror-shortcut-event', command)
}

View file

@ -1,4 +1,4 @@
import { Annotation, Prec } from '@codemirror/state' import { Prec } from '@codemirror/state'
import { keymap } from '@codemirror/view' import { keymap } from '@codemirror/view'
import { toggleRanges } from '../../commands/ranges' import { toggleRanges } from '../../commands/ranges'
@ -9,16 +9,14 @@ export const shortcuts = () => {
key: 'Ctrl-b', key: 'Ctrl-b',
mac: 'Mod-b', mac: 'Mod-b',
preventDefault: true, preventDefault: true,
run: toggleRanges('\\textbf', runShortcut.of('toggle-bold')), run: toggleRanges('\\textbf'),
}, },
{ {
key: 'Ctrl-i', key: 'Ctrl-i',
mac: 'Mod-i', mac: 'Mod-i',
preventDefault: true, preventDefault: true,
run: toggleRanges('\\textit', runShortcut.of('toggle-italic')), run: toggleRanges('\\textit'),
}, },
]) ])
) )
} }
export const runShortcut = Annotation.define<string>()