MSHTML Editor and Carriage Returns... they don't work (well).
I have a span, this one:
---
<span id='formMComment' name='formMComment' contentEditable=true class="fieldtextarea"
onKeyDown = "KeyDoer(this);"
style="{width:888px; height:140px; padding:7px; border:2px inset;}"><%Response.write Trim(rsArray(9,0))%></span>
---
And, then i have a function that, when the ENTER key is hit, triggers this code (this is the portion of the function that deals with the ENTER key only):
--
case 13: //enter-carriage_return
var br = '<br> ';
var ddd = document.selection.createRange();
elem.caretPos = document.selection.createRange();
var caretPos = elem.caretPos;
caretPos.pasteHTML(br);
elem.innerHTML = elem.innerHTML + " ";
event.returnValue = false;
break;
--
Now, the behavior i'm trying to avoid (G-d, smite MicroSoft), is when a user hits ENTER the MSHTML Editor "decides" to inject the paragraph tags, <P> and </P>, injecting into the text what visually appears to the user as 3 carriage returns. Who would want three carriage returns ever time they hit ENTER???? So, for every hit of ENTER the user gets what visually looks like 3 hits of ENTER... less than good, totally.
Thus, i developed the above work around (that injects a <BR> followed by hard space " ", avoiding the whole <P> silliness of Microsoft).
But, the problem gets better, but in a more discrete way:
The reason i follow the <BR> with a hard space is that, without it, the <BR> doesn't get rendered until the user clicks into the contenteditable span. Weird that it only renders with a click, or some other character getting hit. So, it works, but visually is disconcerting to the user as they never get a carriage-return until they continue typing (if i don't code a " " following the <BR> ), or if i don't code the whole " " thing, then the <BR> only renders when the user types the next character -- only then does the <BR> take effect.
I tried a fireEvent("onclick"), and even a object.click(); to no avail.
Any ideas? Hope i've been clear on this, but if not, don't hesitate to message me for further details.
I'm stuck.
.rob
[This message has been edited by Egoz (edited 09-19-2002).]