From ec6b17eb01fe98b8ed66666a99c409e97c3c5c90 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Wed, 21 Aug 2024 10:45:28 +0200 Subject: [PATCH] revert trackChanges extension to a version before redesign GitOrigin-RevId: fc12968a3971cfee7594720076bb4dc271178e73 --- .../source-editor/extensions/index.ts | 6 +- .../source-editor/extensions/track-changes.ts | 105 ++++-------------- 2 files changed, 27 insertions(+), 84 deletions(-) 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 69ed4125c1..b1d7f393f2 100644 --- a/services/web/frontend/js/features/source-editor/extensions/index.ts +++ b/services/web/frontend/js/features/source-editor/extensions/index.ts @@ -49,6 +49,8 @@ import { geometryChangeEvent } from './geometry-change-event' import { docName } from './doc-name' import { fileTreeItemDrop } from './file-tree-item-drop' import { mathPreview } from './math-preview' +import { isSplitTestEnabled } from '@/utils/splitTestUtils' +import { ranges } from './ranges' const moduleExtensions: Array<() => Extension> = importOverleafModules( 'sourceEditorExtensions' @@ -124,7 +126,9 @@ export const createExtensions = (options: Record): Extension[] => [ // NOTE: `emptyLineFiller` needs to be before `trackChanges`, // so the decorations are added in the correct order. emptyLineFiller(), - trackChanges(options.currentDoc, options.changeManager), + isSplitTestEnabled('review-panel-redesign') + ? ranges(options.currentDoc, options.changeManager) + : trackChanges(options.currentDoc, options.changeManager), visual(options.visual), mathPreview(options.settings.mathPreview), toolbarPanel(), diff --git a/services/web/frontend/js/features/source-editor/extensions/track-changes.ts b/services/web/frontend/js/features/source-editor/extensions/track-changes.ts index 1f557af5d6..461b8f78ca 100644 --- a/services/web/frontend/js/features/source-editor/extensions/track-changes.ts +++ b/services/web/frontend/js/features/source-editor/extensions/track-changes.ts @@ -29,14 +29,6 @@ import { DocumentContainer, RangesTrackerWithResolvedThreadIds, } from '@/features/ide-react/editor/document-container' -import { Ranges } from '@/features/review-panel-new/context/ranges-context' -import { Threads } from '@/features/review-panel-new/context/threads-context' -import { isSplitTestEnabled } from '@/utils/splitTestUtils' - -type RangesData = { - ranges: Ranges - threads: Threads -} const clearChangesEffect = StateEffect.define() const buildChangesEffect = StateEffect.define() @@ -54,9 +46,7 @@ const restoreDetachedCommentsEffect = StateEffect.define>({ type Options = { currentDoc: DocumentContainer - loadingThreads?: boolean - ranges?: Ranges - threads?: Threads + loadingThreads: boolean } /** @@ -64,8 +54,8 @@ type Options = { * and produces decorations for tracked changes and comments. */ export const trackChanges = ( - { currentDoc, loadingThreads, ranges, threads }: Options, - changeManager?: ChangeManager + { currentDoc, loadingThreads }: Options, + changeManager: ChangeManager ) => { // A state field that stored any comments found within the ranges of a "cut" transaction, // to be restored when pasting matching text. @@ -130,36 +120,18 @@ export const trackChanges = ( cutCommentsState, // initialize/destroy the change manager, and handle any updates - changeManager - ? ViewPlugin.define(() => { - changeManager.initialize() + ViewPlugin.define(() => { + changeManager.initialize() - return { - update: update => { - changeManager.handleUpdate(update) - }, - destroy: () => { - changeManager.destroy() - }, - } - }) - : ViewPlugin.define(view => { - let timer: number - - return { - update(update) { - if (update.viewportChanged) { - if (timer) { - window.clearTimeout(timer) - } - - timer = window.setTimeout(() => { - dispatchEvent(new Event('editor:viewport-changed')) - }, 25) - } - }, - } - }), + return { + update: update => { + changeManager.handleUpdate(update) + }, + destroy: () => { + changeManager.destroy() + }, + } + }), // draw change decorations ViewPlugin.define< @@ -168,20 +140,10 @@ export const trackChanges = ( } >( () => { - let decorations = Decoration.none - if (isSplitTestEnabled('review-panel-redesign')) { - if (ranges && threads) { - decorations = buildChangeDecorations(currentDoc, { - ranges, - threads, - }) - } - } else if (!loadingThreads) { - decorations = buildChangeDecorations(currentDoc) - } - return { - decorations, + decorations: loadingThreads + ? Decoration.none + : buildChangeDecorations(currentDoc), update(update) { for (const transaction of update.transactions) { this.decorations = this.decorations.map(transaction.changes) @@ -219,23 +181,18 @@ export const buildChangeMarkers = () => { } } -const buildChangeDecorations = ( - currentDoc: DocumentContainer, - data?: RangesData -) => { - const ranges = data ? data.ranges : currentDoc.ranges - - if (!ranges) { +const buildChangeDecorations = (currentDoc: DocumentContainer) => { + if (!currentDoc.ranges) { return Decoration.none } - const changes = [...ranges.changes, ...ranges.comments] + const changes = [...currentDoc.ranges.changes, ...currentDoc.ranges.comments] const decorations = [] for (const change of changes) { try { - decorations.push(...createChangeRange(change, currentDoc, data)) + decorations.push(...createChangeRange(change, currentDoc)) } catch (error) { // ignore invalid changes debugConsole.debug('invalid change position', error) @@ -294,11 +251,7 @@ class ChangeCalloutWidget extends WidgetType { } } -const createChangeRange = ( - change: Change, - currentDoc: DocumentContainer, - data?: RangesData -) => { +const createChangeRange = (change: Change, currentDoc: DocumentContainer) => { const { id, metadata, op } = change const from = op.p @@ -336,20 +289,6 @@ const createChangeRange = ( return [] } - if (_isCommentOperation) { - if (data) { - const thread = data.threads[op.t] - if (!thread || thread.resolved) { - return [] - } - } else if ( - (currentDoc.ranges as RangesTrackerWithResolvedThreadIds) - .resolvedThreadIds![op.t] - ) { - return [] - } - } - const opType = _isCommentOperation ? 'c' : 'i' const changedText = _isCommentOperation ? op.c : op.i const to = from + changedText.length