开发者

Javascript: How to simulate cursor with arrow key control for positioning DOM edits?

开发者 https://www.devze.com 2022-12-22 00:47 出处:网络
I\'m building an in-browser IDE using Javascript.The code/widgets are stored in the document.I want control over the editing 开发者_如何学Goprocess so I am intercepting keystrokes and displaying a sim

I'm building an in-browser IDE using Javascript. The code/widgets are stored in the document. I want control over the editing 开发者_如何学Goprocess so I am intercepting keystrokes and displaying a simulated cursor where the edit point is in the DOM. (At first I tried using contenteditable = true but that isn't giving me enough control.)

I've made some progress so that clicking will insert the cursor at the beginning of the div and the right arrow will move to the next node, although now I am realizing that I am going to have to dig into the contents() and keep track of my cursor position in text nodes..

I'm wondering if anyone knows of any code out there that I can refer to or just copy or something rather than re-inventing the wheel. I am using jQuery but that isn't a requirement.


Perhaps Mozilla Bespin can help. But IMHO if you can't use contenteditable you'll need to write a lot of code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号