mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-20 22:12:38 +00:00
remove clearChanges and buildChanges effects from ranges extension
GitOrigin-RevId: 4782725bfaf50153007bbd9ae5c8146cca769cde
This commit is contained in:
parent
dc70054caf
commit
be47b27d98
2 changed files with 32 additions and 108 deletions
|
@ -128,7 +128,7 @@ export const createExtensions = (options: Record<string, any>): Extension[] => [
|
||||||
// so the decorations are added in the correct order.
|
// so the decorations are added in the correct order.
|
||||||
emptyLineFiller(),
|
emptyLineFiller(),
|
||||||
isSplitTestEnabled('review-panel-redesign')
|
isSplitTestEnabled('review-panel-redesign')
|
||||||
? ranges(options.currentDoc, options.changeManager)
|
? ranges(options.currentDoc)
|
||||||
: trackChanges(options.currentDoc, options.changeManager),
|
: trackChanges(options.currentDoc, options.changeManager),
|
||||||
trackDetachedComments(options.currentDoc),
|
trackDetachedComments(options.currentDoc),
|
||||||
visual(options.visual),
|
visual(options.visual),
|
||||||
|
|
|
@ -12,21 +12,16 @@ import {
|
||||||
DeleteOperation,
|
DeleteOperation,
|
||||||
EditOperation,
|
EditOperation,
|
||||||
} from '../../../../../types/change'
|
} from '../../../../../types/change'
|
||||||
import { ChangeManager } from './changes/change-manager'
|
|
||||||
import { debugConsole } from '@/utils/debugging'
|
import { debugConsole } from '@/utils/debugging'
|
||||||
import {
|
import {
|
||||||
isCommentOperation,
|
isCommentOperation,
|
||||||
isDeleteOperation,
|
isDeleteOperation,
|
||||||
isInsertOperation,
|
isInsertOperation,
|
||||||
} from '@/utils/operations'
|
} from '@/utils/operations'
|
||||||
import {
|
import { DocumentContainer } from '@/features/ide-react/editor/document-container'
|
||||||
DocumentContainer,
|
|
||||||
RangesTrackerWithResolvedThreadIds,
|
|
||||||
} from '@/features/ide-react/editor/document-container'
|
|
||||||
import { trackChangesAnnotation } from '@/features/source-editor/extensions/realtime'
|
import { trackChangesAnnotation } from '@/features/source-editor/extensions/realtime'
|
||||||
import { Ranges } from '@/features/review-panel-new/context/ranges-context'
|
import { Ranges } from '@/features/review-panel-new/context/ranges-context'
|
||||||
import { Threads } from '@/features/review-panel-new/context/threads-context'
|
import { Threads } from '@/features/review-panel-new/context/threads-context'
|
||||||
import { isSplitTestEnabled } from '@/utils/splitTestUtils'
|
|
||||||
|
|
||||||
type RangesData = {
|
type RangesData = {
|
||||||
ranges: Ranges
|
ranges: Ranges
|
||||||
|
@ -41,9 +36,6 @@ export const updateRanges = (data: RangesData): TransactionSpec => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearChangesEffect = StateEffect.define()
|
|
||||||
const buildChangesEffect = StateEffect.define()
|
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
currentDoc: DocumentContainer
|
currentDoc: DocumentContainer
|
||||||
loadingThreads?: boolean
|
loadingThreads?: boolean
|
||||||
|
@ -55,42 +47,26 @@ type Options = {
|
||||||
* A custom extension that initialises the change manager, passes any updates to it,
|
* A custom extension that initialises the change manager, passes any updates to it,
|
||||||
* and produces decorations for tracked changes and comments.
|
* and produces decorations for tracked changes and comments.
|
||||||
*/
|
*/
|
||||||
export const ranges = (
|
export const ranges = ({ ranges, threads }: Options) => {
|
||||||
{ currentDoc, loadingThreads, ranges, threads }: Options,
|
|
||||||
changeManager?: ChangeManager
|
|
||||||
) => {
|
|
||||||
return [
|
return [
|
||||||
// initialize/destroy the change manager, and handle any updates
|
// handle viewportChanged updates
|
||||||
changeManager
|
ViewPlugin.define(view => {
|
||||||
? ViewPlugin.define(() => {
|
let timer: number
|
||||||
changeManager.initialize()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
update: update => {
|
update(update) {
|
||||||
changeManager.handleUpdate(update)
|
if (update.viewportChanged) {
|
||||||
},
|
if (timer) {
|
||||||
destroy: () => {
|
window.clearTimeout(timer)
|
||||||
changeManager.destroy()
|
}
|
||||||
},
|
|
||||||
|
timer = window.setTimeout(() => {
|
||||||
|
dispatchEvent(new Event('editor:viewport-changed'))
|
||||||
|
}, 25)
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
: 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<
|
||||||
|
@ -99,34 +75,18 @@ export const ranges = (
|
||||||
}
|
}
|
||||||
>(
|
>(
|
||||||
() => {
|
() => {
|
||||||
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:
|
||||||
|
ranges && threads
|
||||||
|
? buildChangeDecorations({ ranges, threads })
|
||||||
|
: Decoration.none,
|
||||||
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)
|
||||||
|
|
||||||
for (const effect of transaction.effects) {
|
for (const effect of transaction.effects) {
|
||||||
if (effect.is(clearChangesEffect)) {
|
if (effect.is(updateRangesEffect)) {
|
||||||
this.decorations = Decoration.none
|
this.decorations = buildChangeDecorations(effect.value)
|
||||||
} else if (effect.is(buildChangesEffect)) {
|
|
||||||
this.decorations = buildChangeDecorations(currentDoc)
|
|
||||||
} else if (effect.is(updateRangesEffect)) {
|
|
||||||
this.decorations = buildChangeDecorations(
|
|
||||||
currentDoc,
|
|
||||||
effect.value
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,35 +103,18 @@ export const ranges = (
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const clearChangeMarkers = () => {
|
const buildChangeDecorations = (data: RangesData) => {
|
||||||
return {
|
if (!data.ranges) {
|
||||||
effects: clearChangesEffect.of(null),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const buildChangeMarkers = () => {
|
|
||||||
return {
|
|
||||||
effects: buildChangesEffect.of(null),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const buildChangeDecorations = (
|
|
||||||
currentDoc: DocumentContainer,
|
|
||||||
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 = [...data.ranges.changes, ...data.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, data))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// ignore invalid changes
|
// ignore invalid changes
|
||||||
debugConsole.debug('invalid change position', error)
|
debugConsole.debug('invalid change position', error)
|
||||||
|
@ -230,11 +173,7 @@ class ChangeCalloutWidget extends WidgetType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createChangeRange = (
|
const createChangeRange = (change: Change, data: RangesData) => {
|
||||||
change: Change,
|
|
||||||
currentDoc: DocumentContainer,
|
|
||||||
data?: RangesData
|
|
||||||
) => {
|
|
||||||
const { id, metadata, op } = change
|
const { id, metadata, op } = change
|
||||||
|
|
||||||
const from = op.p
|
const from = op.p
|
||||||
|
@ -264,24 +203,9 @@ const createChangeRange = (
|
||||||
|
|
||||||
const _isCommentOperation = isCommentOperation(op)
|
const _isCommentOperation = isCommentOperation(op)
|
||||||
|
|
||||||
if (
|
|
||||||
_isCommentOperation &&
|
|
||||||
(currentDoc.ranges as RangesTrackerWithResolvedThreadIds)
|
|
||||||
.resolvedThreadIds![op.t]
|
|
||||||
) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_isCommentOperation) {
|
if (_isCommentOperation) {
|
||||||
if (data) {
|
const thread = data.threads[op.t]
|
||||||
const thread = data.threads[op.t]
|
if (!thread || thread.resolved) {
|
||||||
if (!thread || thread.resolved) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
} else if (
|
|
||||||
(currentDoc.ranges as RangesTrackerWithResolvedThreadIds)
|
|
||||||
.resolvedThreadIds![op.t]
|
|
||||||
) {
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue