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

Function getSelectLine

packages/editor/src/plugin/editable.ts:191–224  ·  view source on GitHub ↗

* 获取在选区内选中一行内容的节点以及所在行的索引 * @param editor * @param options * @returns

(
    editor: Editor,
    options: { range?: Range; match?: (element: Element) => boolean } = {},
  )

Source from the content-addressed store, hash-verified

189 * @returns
190 */
191 getSelectLine(
192 editor: Editor,
193 options: { range?: Range; match?: (element: Element) => boolean } = {},
194 ): [Element, number] | undefined {
195 const { range = editor.selection, match = () => true } = options
196 if (!range || Range.isCollapsed(range)) return
197 const start = Range.start(range)
198 const entry = Editor.above(editor, { at: start, match: n => Editor.isBlock(editor, n) })
199 if (!entry) return
200 const rangeLines = getLineRectsByRange(editor, range)
201 let [block, path] = entry
202 while (block) {
203 if (match(block)) {
204 const elLines = getLineRectsByNode(editor, block)
205 for (const rangeLine of rangeLines) {
206 const index = elLines.findIndex(
207 elLine =>
208 elLine.left === rangeLine.left &&
209 elLine.top === rangeLine.top &&
210 elLine.width === rangeLine.width,
211 )
212 if (~index) {
213 return [block, index]
214 }
215 }
216 }
217 const next = Editor.next(editor, { at: path, match: n => Editor.isBlock(editor, n) })
218 if (!next) return
219 const [n, p] = next
220 block = n as Element
221 path = p
222 }
223 return
224 },
225 /**
226 * 检查选区是否选中在内容一行的开始或者结尾
227 * @param editor

Callers

nothing calls this directly

Calls 3

getLineRectsByRangeFunction · 0.90
getLineRectsByNodeFunction · 0.90
matchFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…