Appearance
findClosestChildNode
查找当前位置所在节点下最近的满足条件的子孙节点(深度优先)。
用法
ts
import { findClosestChildNode } from '@qingpai/utils'
const $pos = editor.state.doc.resolve(pos)
const result = findClosestChildNode($pos, node => node.type.name === 'image')参数
| 名称 | 类型 | 描述 |
|---|---|---|
$pos | ResolvedPos | 文档中的解析位置 |
predicate | (node: PMNode) => boolean | 节点匹配条件 |
返回值
NodeInfo | undefined — 匹配到的节点信息;未找到时返回 undefined。
ts
interface NodeInfo {
node: PMNode
/** 节点在文档中的绝对位置 */
pos: number
/** 节点内容的起始位置 */
start: number
/** 节点嵌套深度 */
depth: number
}