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 { 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<string, any>): 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(),

View file

@ -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<RangeSet<any>>({
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