hinesboy / mavonEditor

mavonEditor - A markdown editor based on Vue that supports a variety of personalized features
http://www.mavoneditor.com/
MIT License
6.45k stars 918 forks source link

[Feature] 请增加定位光标位置的事件 #689

Open CrazyMeeee opened 3 years ago

CrazyMeeee commented 3 years ago

🚀 Feature Proposal

在利用toolbar-before/after位置添加自定义组件时,经常遇到需要定位光标位置的问题,需要一个事件来满足这个需求。虽然能通过自定义文件能把这个需求做好,但是我不太知道怎么把这个内容放到远程项目路径下让他能被项目用起来,所以可能需要作者帮忙一下……

Example

emitCursorPosNow() { let cursorIndex = 0; let obj = this.$refs.vNoteTextarea.$refs.vTextarea; if (document.selection) { obj.focus();var range = document.selection.createRange(); range.moveStart('character', -obj.value.length); cursorIndex = range.text.length; } else if (obj.selectionStart || obj.selectionStart==0) { cursorIndex = obj.selectionStart; } this.$emit('CursorPosNow', cursorIndex); }