From 54c55360c409cef6df0120a787e3b6de4c6a1ab1 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 7 Nov 2023 11:49:50 +0000 Subject: [PATCH] Remove completion and shortcut event logging (#15633) GitOrigin-RevId: 35eedb7b18200badef8226eecc58b3c35344f256 --- .../features/source-editor/commands/ranges.ts | 14 ++-------- .../extensions/completion-logger.ts | 28 ------------------- .../source-editor/extensions/index.ts | 4 --- .../extensions/shortcut-logger.ts | 20 ------------- .../extensions/toolbar/utils/analytics.ts | 8 ------ .../languages/latex/shortcuts.ts | 8 ++---- 6 files changed, 6 insertions(+), 76 deletions(-) delete mode 100644 services/web/frontend/js/features/source-editor/extensions/completion-logger.ts delete mode 100644 services/web/frontend/js/features/source-editor/extensions/shortcut-logger.ts diff --git a/services/web/frontend/js/features/source-editor/commands/ranges.ts b/services/web/frontend/js/features/source-editor/commands/ranges.ts index 2267db7e5b..a98e81d0ad 100644 --- a/services/web/frontend/js/features/source-editor/commands/ranges.ts +++ b/services/web/frontend/js/features/source-editor/commands/ranges.ts @@ -1,10 +1,5 @@ import { EditorView } from '@codemirror/view' -import { - EditorSelection, - EditorState, - SelectionRange, - TransactionSpec, -} from '@codemirror/state' +import { EditorSelection, EditorState, SelectionRange } from '@codemirror/state' import { ensureSyntaxTree, foldedRanges, @@ -413,10 +408,7 @@ function bubbleUpRange( return range } -export function toggleRanges( - command: string, - annotations?: TransactionSpec['annotations'] -) { +export function toggleRanges(command: string) { /* There are a number of situations we need to handle in this function. * 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 return wrapRangeInCommand(view.state, range, command) }), - { scrollIntoView: true, annotations } + { scrollIntoView: true } ) return true } diff --git a/services/web/frontend/js/features/source-editor/extensions/completion-logger.ts b/services/web/frontend/js/features/source-editor/extensions/completion-logger.ts deleted file mode 100644 index 2e4ab314ea..0000000000 --- a/services/web/frontend/js/features/source-editor/extensions/completion-logger.ts +++ /dev/null @@ -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 -} diff --git a/services/web/frontend/js/features/source-editor/extensions/index.ts b/services/web/frontend/js/features/source-editor/extensions/index.ts index ef0338ad08..9994ad3aab 100644 --- a/services/web/frontend/js/features/source-editor/extensions/index.ts +++ b/services/web/frontend/js/features/source-editor/extensions/index.ts @@ -47,8 +47,6 @@ import { effectListeners } from './effect-listeners' import { highlightSpecialChars } from './highlight-special-chars' import { toolbarPanel } from './toolbar/toolbar-panel' import { geometryChangeEvent } from './geometry-change-event' -import { completionLogger } from './completion-logger' -import { shortcutLogger } from './shortcut-logger' const moduleExtensions: Array<() => Extension> = importOverleafModules( 'sourceEditorExtensions' @@ -130,8 +128,6 @@ export const createExtensions = (options: Record): Extension[] => [ // The built-in extension that highlights the active line in the gutter. highlightActiveLineGutter(), inlineBackground(options.visual.visual), - completionLogger, - shortcutLogger, codemirrorDevTools(), exceptionLogger(), // CodeMirror extensions provided by modules diff --git a/services/web/frontend/js/features/source-editor/extensions/shortcut-logger.ts b/services/web/frontend/js/features/source-editor/extensions/shortcut-logger.ts deleted file mode 100644 index 471e4326ec..0000000000 --- a/services/web/frontend/js/features/source-editor/extensions/shortcut-logger.ts +++ /dev/null @@ -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) - } - } - }, - } -}) diff --git a/services/web/frontend/js/features/source-editor/extensions/toolbar/utils/analytics.ts b/services/web/frontend/js/features/source-editor/extensions/toolbar/utils/analytics.ts index 6a42045a7c..fa05dd54da 100644 --- a/services/web/frontend/js/features/source-editor/extensions/toolbar/utils/analytics.ts +++ b/services/web/frontend/js/features/source-editor/extensions/toolbar/utils/analytics.ts @@ -14,11 +14,3 @@ export function emitCommandEvent( export function emitToolbarEvent(view: EditorView, command: string) { 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) -} diff --git a/services/web/frontend/js/features/source-editor/languages/latex/shortcuts.ts b/services/web/frontend/js/features/source-editor/languages/latex/shortcuts.ts index c09572643b..00859605d5 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/shortcuts.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/shortcuts.ts @@ -1,4 +1,4 @@ -import { Annotation, Prec } from '@codemirror/state' +import { Prec } from '@codemirror/state' import { keymap } from '@codemirror/view' import { toggleRanges } from '../../commands/ranges' @@ -9,16 +9,14 @@ export const shortcuts = () => { key: 'Ctrl-b', mac: 'Mod-b', preventDefault: true, - run: toggleRanges('\\textbf', runShortcut.of('toggle-bold')), + run: toggleRanges('\\textbf'), }, { key: 'Ctrl-i', mac: 'Mod-i', preventDefault: true, - run: toggleRanges('\\textit', runShortcut.of('toggle-italic')), + run: toggleRanges('\\textit'), }, ]) ) } - -export const runShortcut = Annotation.define()