revert trackChanges extension to a version before redesign

GitOrigin-RevId: fc12968a3971cfee7594720076bb4dc271178e73
This commit is contained in:
Domagoj Kriskovic 2024-08-21 10:45:28 +02:00 committed by Copybot
parent 6547ce6aa1
commit ec6b17eb01
2 changed files with 27 additions and 84 deletions

View file

@ -49,6 +49,8 @@ import { geometryChangeEvent } from './geometry-change-event'
import { docName } from './doc-name' import { docName } from './doc-name'
import { fileTreeItemDrop } from './file-tree-item-drop' import { fileTreeItemDrop } from './file-tree-item-drop'
import { mathPreview } from './math-preview' import { mathPreview } from './math-preview'
import { isSplitTestEnabled } from '@/utils/splitTestUtils'
import { ranges } from './ranges'
const moduleExtensions: Array<() => Extension> = importOverleafModules( const moduleExtensions: Array<() => Extension> = importOverleafModules(
'sourceEditorExtensions' 'sourceEditorExtensions'
@ -124,7 +126,9 @@ export const createExtensions = (options: Record<string, any>): Extension[] => [
// NOTE: `emptyLineFiller` needs to be before `trackChanges`, // NOTE: `emptyLineFiller` needs to be before `trackChanges`,
// so the decorations are added in the correct order. // so the decorations are added in the correct order.
emptyLineFiller(), emptyLineFiller(),
trackChanges(options.currentDoc, options.changeManager), isSplitTestEnabled('review-panel-redesign')
? ranges(options.currentDoc, options.changeManager)
: trackChanges(options.currentDoc, options.changeManager),
visual(options.visual), visual(options.visual),
mathPreview(options.settings.mathPreview), mathPreview(options.settings.mathPreview),
toolbarPanel(), toolbarPanel(),

View file

@ -29,14 +29,6 @@ import {
DocumentContainer, DocumentContainer,
RangesTrackerWithResolvedThreadIds, RangesTrackerWithResolvedThreadIds,
} from '@/features/ide-react/editor/document-container' } 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 clearChangesEffect = StateEffect.define()
const buildChangesEffect = StateEffect.define() const buildChangesEffect = StateEffect.define()
@ -54,9 +46,7 @@ const restoreDetachedCommentsEffect = StateEffect.define<RangeSet<any>>({
type Options = { type Options = {
currentDoc: DocumentContainer currentDoc: DocumentContainer
loadingThreads?: boolean loadingThreads: boolean
ranges?: Ranges
threads?: Threads
} }
/** /**
@ -64,8 +54,8 @@ type Options = {
* and produces decorations for tracked changes and comments. * and produces decorations for tracked changes and comments.
*/ */
export const trackChanges = ( export const trackChanges = (
{ currentDoc, loadingThreads, ranges, threads }: Options, { currentDoc, loadingThreads }: Options,
changeManager?: ChangeManager changeManager: ChangeManager
) => { ) => {
// A state field that stored any comments found within the ranges of a "cut" transaction, // A state field that stored any comments found within the ranges of a "cut" transaction,
// to be restored when pasting matching text. // to be restored when pasting matching text.
@ -130,36 +120,18 @@ export const trackChanges = (
cutCommentsState, cutCommentsState,
// initialize/destroy the change manager, and handle any updates // initialize/destroy the change manager, and handle any updates
changeManager ViewPlugin.define(() => {
? ViewPlugin.define(() => { changeManager.initialize()
changeManager.initialize()
return { return {
update: update => { update: update => {
changeManager.handleUpdate(update) changeManager.handleUpdate(update)
}, },
destroy: () => { destroy: () => {
changeManager.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)
}
},
}
}),
// draw change decorations // draw change decorations
ViewPlugin.define< 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 { return {
decorations, decorations: loadingThreads
? Decoration.none
: buildChangeDecorations(currentDoc),
update(update) { update(update) {
for (const transaction of update.transactions) { for (const transaction of update.transactions) {
this.decorations = this.decorations.map(transaction.changes) this.decorations = this.decorations.map(transaction.changes)
@ -219,23 +181,18 @@ export const buildChangeMarkers = () => {
} }
} }
const buildChangeDecorations = ( const buildChangeDecorations = (currentDoc: DocumentContainer) => {
currentDoc: DocumentContainer, if (!currentDoc.ranges) {
data?: RangesData
) => {
const ranges = data ? data.ranges : currentDoc.ranges
if (!ranges) {
return Decoration.none return Decoration.none
} }
const changes = [...ranges.changes, ...ranges.comments] const changes = [...currentDoc.ranges.changes, ...currentDoc.ranges.comments]
const decorations = [] const decorations = []
for (const change of changes) { for (const change of changes) {
try { try {
decorations.push(...createChangeRange(change, currentDoc, data)) decorations.push(...createChangeRange(change, currentDoc))
} catch (error) { } catch (error) {
// ignore invalid changes // ignore invalid changes
debugConsole.debug('invalid change position', error) debugConsole.debug('invalid change position', error)
@ -294,11 +251,7 @@ class ChangeCalloutWidget extends WidgetType {
} }
} }
const createChangeRange = ( const createChangeRange = (change: Change, currentDoc: DocumentContainer) => {
change: Change,
currentDoc: DocumentContainer,
data?: RangesData
) => {
const { id, metadata, op } = change const { id, metadata, op } = change
const from = op.p const from = op.p
@ -336,20 +289,6 @@ const createChangeRange = (
return [] 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 opType = _isCommentOperation ? 'c' : 'i'
const changedText = _isCommentOperation ? op.c : op.i const changedText = _isCommentOperation ? op.c : op.i
const to = from + changedText.length const to = from + changedText.length