Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Carriage Returns


Message #1 by "Robert Adams" <rob@e...> on Wed, 18 Sep 2002 21:41:27
Continuing my journey contenteditable and textrange (mshtml editor), how 
about carriage returns?

Native to the MSHTML Editor, (making, say, a span contenteditable) if the 
user clicks ENTER, then the Editor implants the paragraph opening and 
closing tags (P's) into the body.  This is less-than-good, because it not 
only causes one carriage return, but the equivalent of about 3-4, causing 
a huge jump of the cursor downwards.

So, i'm trying to get the effect of a normal editor when the user hits the 
ENTER key...  a single carriage return, not many.

Here's the section of my code that does this:
-------
case 13:		//enter-carriage_return
	var br = '\n<br>';
	var ddd = document.selection.createRange();
	elem.caretPos = document.selection.createRange();
	
	var caretPos = elem.caretPos;
	//elem.innerHTML = elem.innerHTML + "/n/n<br>";
	caretPos.pasteHTML(br);
		
	event.returnValue = false;
	break;
--------
Here's the problem, it does insert a BR, but it does not cause the cursor 
to carriage return and go to the line below, until the user clicks another 
character on the keyboard.  It's almost like its rendering the HTML, in 
total, when the user clicks another character.
The commented out part (elem.innerHTML = ...) works the same way as the 
uncommented-out line (caretPos.pasteHTML(br);)

Any ideas?

.rob
rob@e...

  Return to Index