Files
overleaf-cep/services/web/frontend/js/utils/operations.ts
David 584572bb40 Merge pull request #28760 from overleaf/dp-hackathon-knip
Add Knip and remove a bunch of unused code

GitOrigin-RevId: 42ab99fc65973c883d2361e0027e7181767e714e
2025-10-15 08:05:57 +00:00

40 lines
997 B
TypeScript

import {
AnyOperation,
Change,
CommentOperation,
DeleteOperation,
EditOperation,
InsertOperation,
Operation,
} from '../../../types/change'
export const isInsertOperation = (op: Operation): op is InsertOperation =>
'i' in op
export const isCommentOperation = (op: Operation): op is CommentOperation =>
'c' in op
export const isDeleteOperation = (op: Operation): op is DeleteOperation =>
'd' in op
export const isEditOperation = (op: Operation): op is EditOperation =>
isInsertOperation(op) || isDeleteOperation(op)
export const isInsertChange = (
change: Change<EditOperation>
): change is Change<InsertOperation> => isInsertOperation(change.op)
export const isDeleteChange = (
change: Change<EditOperation>
): change is Change<DeleteOperation> => isDeleteOperation(change.op)
export const visibleTextLength = (op: AnyOperation) => {
if (isCommentOperation(op)) {
return op.c.length
}
if (isInsertOperation(op)) {
return op.i.length
}
return 0
}