gpt4 book ai didi

javascript - 在 draft.js 中获取插入符位置(行号)

转载 作者:行者123 更新时间:2023-12-02 04:02:13 25 4
gpt4 key购买 nike

你如何获得 draft.js 中的插入符位置?我猜你可以从selectionstate中获取 block ,然后获取 block 数组,看看 block 数组在哪个位置,但我不确定这是一种可靠的方式,甚至是最好的方式。

最佳答案

不确定这是不是你的意思,但你可以像这样获取当前 block 的索引:

const currentBlockKey = editorState.getSelection().getStartKey()
const currentBlockIndex = editorState.getCurrentContent().getBlockMap()
.keySeq().findIndex(k => k === currentBlockKey)

这是一个带有完整示例的 fiddle :https://jsfiddle.net/cczhL821/

关于javascript - 在 draft.js 中获取插入符位置(行号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41353569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com