Reputation: 504
I'm developping a markdown editor with node-webkit (Chromium 38.0.2125.104) that convert the markdown to html while typing, and render it in the same contenteditable (kind of highlighting). So everything works fine this way : i save the caret position by inserting a new node in the dom. Then i process my text. Then i get back the caret position and delete my marker node.
My problem is that i try to do all this as fast as i can. But more than half of the process time is taken by a single opération :
selection.removeAllRanges();
After having done everything and just before adding my created range to the selection object. Around 15/20 ms lost into one operation, something that starts to feel when typing fast. Is there any way i could speed it up, like calling something else, or work a different way with the selection/ranges ? thank you (i mean it, i always used this site for answers, but this is my first question)
Upvotes: 2
Views: 565
Reputation: 324477
If you're only interested in Chrome, you could try using the non-standard WebKit method setBaseAndExtent()
(sorry, no documentation link because as far as I can tell it's never been documented) to set the selection directly. I have no idea if it will be any faster; I can't see why it would be.
Assuming your range is stored in a variable called range
and your selection in sel
:
sel.setBaseAndExtent(range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
Upvotes: 2