liuhong1happy / react-umeditor

React Editor like Umeditor
MIT License
279 stars 77 forks source link

请问一下,如何让toolbar固定在顶部,还有insert一段代码的时候怎样获得当前鼠标位置 #79

Open gy-l opened 5 years ago

gy-l commented 5 years ago

第一个问题:为了避免页面太长我给Editor加了style,我加了overflowY:'scroll',但发现toolbar会跟随滚动,请问我需要怎样让toolbar fixed在顶部? <Editor style={{height: 600,overflowY:'scroll'}} ref="editor" icons={this.icons} defaultValue={this.defaultChange()} onChange={this.handleChange()} plugins={plugins} /> scroll

第二个问题:我们业务的需求需要插入一种或一种以上公共的title 所以我大概试着插入了一下,发现editarea.focus();并不是指的是鼠标位置,而是整个内容,所以每一次插入的时候都插入在底部了。 toolbar: { icons: [{ name: 'autotypeset', title: "模板标题", className: "editor-icon icon-autotypeset", onIconClick:({ editarea})=> { editarea.focus(); editarea.innerHTML += '标题模板'; }, }] } insert

liuhong1happy commented 5 years ago

你好!感谢使用编辑器。 让toolbar固定,使用更改编辑器css样式的方法来实现,外层position:relative;内层positon:aboslute;或者postion:fixed; 获取当前光标位置,请参考 https://github.com/liuhong1happy/react-umeditor-example/blob/aedcbccdef0c20fb3a9f68c961570700dcc9a199/src/components/plugin/toolbar.jsx#L35 其中EditorSelection.range为当前光标,插入内容的方法则参考toolbar.jsx。