mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-15 16:00:57 -05:00
8a90ffa3fb
* Add showGenericConfirmModal in ModalsContext * Add confirm modal on accept/reject selected changes * plural in translations * change tooltip to include selected changes * add _plural to all translated languages * lowercase title/tooltip * count replacements as single change * use new translation key GitOrigin-RevId: afadbe1eeb2a290688b96f2b5388485f40c958d0
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { SelectionRange } from '@codemirror/state'
|
|
import { Ranges } from '@/features/review-panel-new/context/ranges-context'
|
|
import { isDeleteChange, isInsertChange } from '@/utils/operations'
|
|
import { canAggregate } from './can-aggregate'
|
|
import { Change, EditOperation } from '../../../../../types/change'
|
|
|
|
export function numberOfChangesInSelection(
|
|
ranges: Ranges | undefined,
|
|
selection: SelectionRange
|
|
) {
|
|
if (!ranges) {
|
|
return 0
|
|
}
|
|
|
|
let count = 0
|
|
let precedingChange: Change<EditOperation> | null = null
|
|
|
|
for (const change of ranges.changes) {
|
|
if (
|
|
precedingChange &&
|
|
isInsertChange(precedingChange) &&
|
|
isDeleteChange(change) &&
|
|
canAggregate(change, precedingChange)
|
|
) {
|
|
// only count once for the aggregated change
|
|
continue
|
|
} else if (
|
|
isInsertChange(change) &&
|
|
change.op.p >= selection.from &&
|
|
change.op.p + change.op.i.length <= selection.to
|
|
) {
|
|
count++
|
|
} else if (
|
|
isDeleteChange(change) &&
|
|
selection.from <= change.op.p &&
|
|
change.op.p <= selection.to
|
|
) {
|
|
count++
|
|
}
|
|
precedingChange = change
|
|
}
|
|
|
|
return count
|
|
}
|