goog editor: dom manipulation before change

45 views
Skip to first unread message

dali

unread,
May 14, 2013, 5:40:46 AM5/14/13
to closure-lib...@googlegroups.com
Hi,
I have a closure editor div which contains nested elements with text nodes. So, whenever a user makes changes, I need to make some changes to the user command *before* applying the changes.
Eg, if user selects a range across div structure and presses an alpha key, I need to
1. change the range delete to only delete text nodes, not the nested elements
2. follow through on the user key press
I'm currently using the handleKeyPress function in a custom plugin.
#1 works like this, but: I don't know how to easily "re-trigger" the alpha key press
Also: I haven't figured out whether there's a "beforeKeyPress" or something I could use instead? I assume then I could just do #1 and let the browser work on #2. This would be ideal  - do you have any hints for what could be useful here?

(I've also played with the BEFORECHANGE event, but listening to it directly seems to not recommended for performance, and I didn't find a corresponding "plugin function" such as for the handleKeyXY functions.)

Rhys Brett-Bowen

unread,
May 14, 2013, 10:50:51 AM5/14/13
to closure-lib...@googlegroups.com
try the onkeydown, that should get you the event before anything else happens.

dali

unread,
May 15, 2013, 6:47:07 AM5/15/13
to closure-lib...@googlegroups.com
hey thanks, that led me looking into the right direction.
I'm now using handleKeyDown - I did find out that (at least in FF) handleKeyPress also gets called before the alphanum gets inserted.
In case it's of interest to anyone, the trick then was to simply make a new selection (newrange.select() ) before returning from the function. The char will then get inserted at the new selection.
Now on to handling paste..
Reply all
Reply to author
Forward
0 new messages