import { HIGHLIGHT_SPAN_PATTERN } from '@admin/utils/editor/highlight-span-pattern' export function findHighlightSpanRange( markdown: string, from: number, to: number ): { start: number; end: number; text: string } | null { HIGHLIGHT_SPAN_PATTERN.lastIndex = 0 for (const match of markdown.matchAll(HIGHLIGHT_SPAN_PATTERN)) { const start = match.index const end = start + match[0].length const textStart = start + match[0].indexOf('>') + 1 const textEnd = textStart + match[1].length const cursorInside = from === to && from >= start && from <= end const selectionInside = from >= textStart && to <= textEnd const selectionCovers = from <= start && to >= end if (cursorInside || selectionInside || selectionCovers) { return { start, end, text: match[1] } } } return null }