- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 editorState 上做了一些棘手的状态突变,我失去了选择。
我需要获取 currentText(),使用一些神奇的库将其转换为 HTML,然后将其转换回 editorState。这很好用,只是选择太难了。
现在,我试图在第一个开始时获得选择,然后执行 forceSelection
,但由于一些与 selection.hasFocus()
相关的错误而失败(这似乎并没有真正相关...)。
我猜我需要根据 anchor 和偏移量计算"new"选择,但不确定,有什么想法可以做到这一点吗?
现在我的代码是这样的:
// onChangeHandler:
const currentContentState = editorState.getCurrentContent()
const selectionState = editorState.getSelection()
const plainHtml = magicOperation(currentContentState.getPlainText())
const currentContentBlocks = convertFromHTML(plainHtml)
const contentState = ContentState.createFromBlockArray(currentContentBlocks)
const newEditorState = EditorState.createWithContent(contentState)
this.setState({
editorState: EditorState.forceSelection(
newEditorState,
selectionState
)
})
是 hack,我知道我只是在玩 DraftJS 如果我能做到这一点,在我让它顺利工作的情况下,我肯定会使用装饰器在 editorState 中添加 HTML。
感谢您的宝贵时间!
最佳答案
selectionState包含 block 键 (anchorKey&focusKey)。键变了,因为你替换了整个 block 。您需要做的是从偏移中找到键并将其设置为新的 selectionState,然后再将其应用到新的 editorState。
我很感兴趣,为什么您需要将纯文本转换为 html 并返回。
关于reactjs - 突变后失去选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38749474/
我在我的项目(Ubuntu 18.04.2 LTS)中使用了 celery 4.4.0 版本。当我提出异常('功能中的功能太少无法分类')时, celery 项目失去了 worker ,我得到了这样的
我在这样的更新面板中有一个 GridView :
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎不是关于 a specific programming problem,
当我尝试使用 jquery 的 html() 将 HTML 附加到另一个元素时。我失去了 ng-click 的能力。这是我的代码的粗略描述。例如我有一个名为 testController 的 Cont
我正在将 python 连接到 mySqL 数据库,并从 android 发送两个 Double 值以存储在 Mysql 中,然后我收到此错误 enter code here Exception i
无法理解为什么这个简单的事情没有反应性。看起来我错过了一些 Vue 的基础。 {{connection_status}} export default {
我不明白出了什么问题,在我的设备上应用程序运行良好,但有时在日志中(应用程序用户、 session 、崩溃......通过某些服务跟踪)我看到应用程序崩溃(NullPointerException),
我正在处理一个我有点困惑的问题。问题是假设您是二战期间英国空军的一名将军。您还剩下 100 架飞机来保卫英国。在您执行的每个任务中,每架飞机都有 50% 的几率被德国高射炮击落,因此每次执行任务您都会
我相信我的问题与以下问题非常相似 Spring security 'remember me' cookie not avaiable in first request . 基本上,我有一组用于公司内部
似乎 Bootstrap 下拉按钮在单击后仍保持焦点。 我的用例与此不兼容, 用户应该在单击按钮后按“SPACE”键,为了触发与按钮无关的东西。 问题是按钮保持焦点状态,因此按空格键 激活按钮。 我希
我有一个 MKMapView,其中有很多从解析器 xml 定义的注释引脚;那是我的代码: -(IBAction)LoadAnnotation:(id)sender { RXML element
我有一个 HTML 表格,用户可以在其中输入他的待机开始时间和待机结束时间,该时间计算总时数,并基于此计算获得的补偿时数。这一切都有效。 现在,它所做的是,每当用户输入开始和结束时间时,用户必须将焦点
Windows 系统更新后,Eclipse 不再了解 Android 的任何信息...我如何恢复对 Android 的支持?我尝试重新安装 SDK,但没有成功... 太奇怪了。我注意到项目模板丢失了,
我正在发送 SOAP 请求来更新某些实体。当我创建(而不是更新)几乎相同的东西时,一切正常。我跟踪了客户端和传输的日志记录,最后它给了我一个线索。它看起来像这样: DEBUG:suds.client:
这个问题在这里已经有了答案: TypeError: Cannot read property 'setState' of undefined (3 个答案) How to access the co
我使用 PostgreSQL 和 repmgrd 创建了一个 Docker 镜像,所有这些镜像都是使用 supervisor 启动的。 我现在的问题是,当它启动时,由 supervisor 生成的 r
新的 iOS 开发者为 iPhone 编写第一个委托(delegate)应用程序。 模态调用的父 View Controller 有六个 subview Controller ,它们使用父 View
我目前正在 MVC4 中创建一些用户配置文件编辑表单,并且为了测试,我将 UserId 属性呈现为表单上的只读文本框,如下所示: @Html.LabelFor(model => model.
我是一名优秀的程序员,十分优秀!