当状态变化时,反应可调的光标会跳到结束

发布于 2025-01-31 07:43:50 字数 1259 浏览 2 评论 0原文

我正在使用此库反应可触摸的

我有一个文本编辑区域,当状态在Redux中变化时,光标会跳到末尾。我希望光标留在编辑停止的位置,

<div className={classes.speaker} ref={myRef}>
    <ContentEditable
        key={position}
            style={{
                flex: 1,
                    display: 'flex',
                    flexWrap: 'wrap',
                    alignItems: 'center'
                }}
            innerRef={contentEditable}
            html={html} // innerHTML of the editable div
            disabled={!editMode} // use true to disable editing
            className={holdingCtrlKey ? 'cursor-pointer' : ''}
            onChange={e => {
                autoSave(e);
            }}
            onClick={e => {
                if (editMode) {
                    setEditingNow(true);
                    setStartingPoint({ ...e.target.dataset });
                }
                handleClick(e);
            }}
            tagName="div" // Use a custom HTML tag (uses a div by default)
    />
</div>

我可以在每个跨越中保存数据位置的跨度位置。 如何将光标保持在编辑停止的位置

”“在此处输入图像描述”

您在图像中看到的,它会在状态更改后跳到末端

I am working with this Library react-contenteditable

I have a text editing area where when the state changes in the redux the cursor jumps to the end. i want the cursor to stay where editing stops

<div className={classes.speaker} ref={myRef}>
    <ContentEditable
        key={position}
            style={{
                flex: 1,
                    display: 'flex',
                    flexWrap: 'wrap',
                    alignItems: 'center'
                }}
            innerRef={contentEditable}
            html={html} // innerHTML of the editable div
            disabled={!editMode} // use true to disable editing
            className={holdingCtrlKey ? 'cursor-pointer' : ''}
            onChange={e => {
                autoSave(e);
            }}
            onClick={e => {
                if (editMode) {
                    setEditingNow(true);
                    setStartingPoint({ ...e.target.dataset });
                }
                handleClick(e);
            }}
            tagName="div" // Use a custom HTML tag (uses a div by default)
    />
</div>

i can get the position of the span as im saving data-position in every span.
How can i keep the cursor where editing stops

enter image description here

As you can see in the image it jumps to the end as soon as the state changes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文