is-selection-within-op.ts 337 B

12345678910
  1. import { AnyOperation } from '../../../../../types/change'
  2. import { SelectionRange } from '@codemirror/state'
  3. import { visibleTextLength } from '@/utils/operations'
  4. export const isSelectionWithinOp = (
  5. op: AnyOperation,
  6. range: SelectionRange
  7. ): boolean => {
  8. return range.to >= op.p && range.from <= op.p + visibleTextLength(op)
  9. }