如何在 textarea 中模拟人工插入符号? [英] How to simulate an artificial caret in a textarea?

查看:30
本文介绍了如何在 textarea 中模拟人工插入符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是类似于协作编辑器的工作方式.我想允许两个人编辑同一个文档.为此,我必须模拟一个人工插入符号.我可以在textarea的指定位置提取其他用户的添加和删除活动.

然后我会将位置和操作一起传输到另一个文档.在那里我需要在发送的坐标处执行所需的更改.我已经搜索并找到了足够的方法来设置插入符号位置并在当前插入符号位置插入或删除文本,但问题是文档的插入符号移动到我进行更改的位置.

我不想那样,我想有两个插入符号,两个用户各一个.将他们的更改传输到其他文档并在各自的位置进行更改,同时显示两个不同的插入符号.

我只需要知道是否有某些库可以使用,或者即使我必须自己制作,那么我应该如何以及从哪里开始.我什至不知道 textarea 在浏览器中是如何表示的.如何在文本区域中表征位置,如果我知道然后我将这些位置保存在内存中并根据收到的输入进行更改.

我希望我说得通,感谢您的帮助.

解决方案

你看到了吗?

https://github.com/benjamn/kix-standalone/

谷歌文档就是这样做的:

https://drive.googleblog.com/2010/05/whats-different-about-new-google-docs.html

What I am trying to do is something similar to how collaborative editor works. I want to allow two people to edit the same document. And for this I have to simulate an artificial caret. I can extract the other user's activity in term of addition and deletion at specified location in a textarea.

I will then transmit the location, along with the action to the other document. There I need to carry out the required change at the sent coordinate. I have searched and found enough ways to set the caret location and insert or delete text at the current caret location, but the problem is that the caret of the document moves to the location at which I make the change.

I don't want that, I want to have two carets, one each for the two users. Transmit their changes to each other documents and make the changes at their respective locations, while showing two different carets.

I just need to know if there are certain libraries that I can use, or even if I have to make this on my own, then how and where do I start. I don't even know how a textarea is represented within a browser. How can I characterize locations within a textarea, if I know that then I save the locations in memory and make the changes based on the input received.

I hope I make sense, thanks for any help.

解决方案

have you seen this?

https://github.com/benjamn/kix-standalone/

This is how google docs does it:

https://drive.googleblog.com/2010/05/whats-different-about-new-google-docs.html

这篇关于如何在 textarea 中模拟人工插入符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆