Vanessa219 / vditor

♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。An In-browser Markdown editor, support WYSIWYG (Rich Text), Instant Rendering (Typora-like) and Split View modes.
https://b3log.org/vditor
MIT License
8.09k stars 844 forks source link

希望增加methods:获取焦点在字符串中的位置 #1628

Closed ZhengZhiGeorge closed 1 month ago

ZhengZhiGeorge commented 2 months ago

你在什么场景下需要该功能?

我自己添加了toolbar中一些工具,可以在焦点位置插入一些字符串(比如公式)。我希望能够获取焦点上下文,比如前后是否有换行,从而判断是否需要额外插入换行。如果能够获取焦点在字符串中的位置,就OK啦

(目前,只能通过getCursorPosition()获取焦点的在编辑器中的坐标。)

描述最优的解决方案

增加methods,能够返回焦点在字符串中的位置index。

Vanessa219 commented 1 month ago

getCursorPosition 已经返回 index,如果不够用的话可以使用 Range 加以识别。

ZhengZhiGeorge commented 1 month ago

能否请教一下具体怎么做? 我用range尝试下来,获取的是在当前段落中的字符串位置。 (另外看到论坛上也有人问这个问题,感觉这个需求还挺典型的

ZhengZhiGeorge commented 1 month ago

@Vanessa219

Vanessa219 commented 1 month ago

这个需要根据你的使用场景来,getCursorPosition 已经可以获取位置了。