Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在光标位置插入内容的问题 #720

Closed
ihewro opened this issue Aug 17, 2020 · 6 comments
Closed

在光标位置插入内容的问题 #720

ihewro opened this issue Aug 17, 2020 · 6 comments
Assignees
Milestone

Comments

@ihewro
Copy link

ihewro commented Aug 17, 2020

请先看《提问的智慧》,并尝试到黑客派搜寻资料解决问题。


编辑模式

  • wysiwyg 所见即所得模式
  • ir 即时渲染模式
  • sv 分屏编辑预览模式

描述问题

https://vditor.b3log.org/demo/method-CRUD.html

这个页面中一开始鼠标点在的用户较为友好,此处文字的后面,
然后点击一下编辑框的外部页面区域,
再次点击在光标位置插入内容按钮,插入的内容插入在编辑器的开头,而不是最后的光标位置

这个需求的场景是,上面的toolbar 自定义了一个事件,点击后出现一个弹窗,然后弹窗中填了一些文字,点击确定,插入文字到编辑器中,结果插入到编辑器的开头位置了

期待的结果

希望点击编辑器外面的页面区域,仍然能记录最后点击编辑器的光标位置

@88250
Copy link
Collaborator

88250 commented Aug 17, 2020

嗯,应该记录最近 n 次光标位置,方便追溯。

@Vanessa219
Copy link
Owner

我也遇到这个问题了,目前临时把 range 存在一个变量里面。看来还是需要解决一下的。

@Vanessa219 Vanessa219 self-assigned this Aug 22, 2020
@Vanessa219 Vanessa219 modified the milestones: 3.4, 3.5 Aug 22, 2020
@Vanessa219 Vanessa219 modified the milestones: 3.5, 3.6 Oct 11, 2020
@ttshangxiang
Copy link

我也遇到这个问题了,目前临时把 range 存在一个变量里面。看来还是需要解决一下的。

你好,请问怎么获取与设置range?

@Vanessa219
Copy link
Owner

目前只能直接使用 JS API getSelection

@KCVO1995
Copy link

KCVO1995 commented Nov 4, 2020

JS API getSelection 只能获取,但是不能设置光标呀,要怎么解决

@Vanessa219
Copy link
Owner

    const selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants