Ticket #571: split_text_on_backspace.htm

File split_text_on_backspace.htm, 630 bytes (added by Hallvord R. M. Steen (Opera Software), 17 years ago)
Line 
1<!DOCTYPE html>
2<html>
3<head><title> keeping range across heavy DOM work on backspace press </title>
4<script>
5document.designMode='On';
6document.onkeypress=function( e ){ if(e.keyCode==8){
7var sourceRange=window.getSelection().getRangeAt(0);
8
9if( 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>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy