MCPcopy Create free account
hub / github.com/editablejs/editable / isRectInLine

Function isRectInLine

packages/editor/src/utils/selection.ts:155–175  ·  view source on GitHub ↗
(rect: DOMRect, line: Record<'top' | 'bottom' | 'height', number>)

Source from the content-addressed store, hash-verified

153 * @return {Boolean} - True if the rect intersects with the line, false otherwise
154 */
155const isRectInLine = (rect: DOMRect, line: Record<'top' | 'bottom' | 'height', number>) => {
156 const deltaEdge = rect.height / 3
157 return (
158 // Check if the rect is fully contained within the line
159 (rect.top >= line.top &&
160 (rect.bottom <= line.bottom ||
161 // Check if the top of the rect is in the line and the overflow of the bottom is within 2/3
162 rect.top + deltaEdge < line.bottom ||
163 // Check if the bottom of the rect is within 2/3 from the top of the line and the top of the rect is above the bottom of the line
164 (rect.top <= line.top + line.height / 3 && rect.bottom > line.top))) ||
165 // Check if the rect covers the height of the line and the line is within the top and bottom of the rect
166 (rect.top <= line.top &&
167 (rect.bottom >= line.bottom ||
168 // Check if the top of the rect is above or equal to the top of the line and the bottom of the rect is within 2/3 of the line
169 rect.bottom - deltaEdge > line.top)) ||
170 // Check if the bottom of the rect is within 2/3 from the bottom of the line and the top of the rect is above the bottom of the line
171 (rect.bottom <= line.bottom &&
172 rect.bottom >= line.bottom - line.height / 3 &&
173 rect.top < line.bottom)
174 )
175}
176/**
177 * Find the maximum position in the line of the top position in the el node
178 * @param editor - The Editor instance

Callers 3

findLineKeyFunction · 0.85
compareHeightFunction · 0.85
getLineRectsByRangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…