| 1 | <!DOCTYPE html> |
|---|
| 2 | <html> |
|---|
| 3 | <head><title> keeping range across heavy DOM work on backspace press </title> |
|---|
| 4 | <script> |
|---|
| 5 | document.designMode='On'; |
|---|
| 6 | document.onkeypress=function( e ){ if(e.keyCode==8){ |
|---|
| 7 | var sourceRange=window.getSelection().getRangeAt(0); |
|---|
| 8 | |
|---|
| 9 | if( sourceRange.endContainer.nodeType==3 ){ |
|---|
| 10 | sourceRange.endContainer.splitText(sourceRange.endOffset); |
|---|
| 11 | sourceRange.endContainer.data+=sourceRange.endContainer.nextSibling.data; |
|---|
| 12 | sourceRange.endContainer.parentNode.removeChild(sourceRange.endContainer.nextSibling); |
|---|
| 13 | } |
|---|
| 14 | } |
|---|
| 15 | } |
|---|
| 16 | </script></head> |
|---|
| 17 | |
|---|
| 18 | <body><p>This is <b>editable</b> text</b></p><p>This sample</p></body></html> |
|---|