Closed Thread Icon

Topic awaiting preservation: MSHTML Editor and Carriage Returns Pages that link to <a href="https://ozoneasylum.com/backlink?for=8319" title="Pages that link to Topic awaiting preservation: MSHTML Editor and Carriage Returns" rel="nofollow" >Topic awaiting preservation: MSHTML Editor and Carriage Returns\

 
Author Thread
Egoz
Nervous Wreck (II) Inmate

From: Boston, MA, USA
Insane since: Sep 2002

posted posted 09-19-2002 15:34

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 + "&nbsp;";

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).]

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 09-19-2002 15:40

I see what you mean here, one thing to consider though. Since the MSHTML Editor is made to work just like MSWord I guess this is intentional.
The normal way in a wordprocessor is that you get a new paragraph on enter (carriage return, if you just want to get a linefeed (<br> ) you hold shift and press enter.

No tip at this time on getting the inserted br in your workaround to render directly though.
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

Egoz
Nervous Wreck (II) Inmate

From: Boston, MA, USA
Insane since: Sep 2002

posted posted 09-19-2002 15:56

Yeah, i begrugingly see your point as to why the MSHTML Editor injects the whole <P> stuff. And, i noticed how, if you do a CTRL-ENTER you get a nice simple <BR>.

One thing that i noticed. If you use just ENTER and get your <P>, you cannot backspace through the paragraph marks. Instead, you need to select the paragraph marks (visually these are, of course, just blank lines in amidst your text) and then hit the delete or backspace key. Only then can a paragraph marker be deleted within your text.

I'll figure this out (i hope).

.rob


« BackwardsOnwards »

Show Forum Drop Down Menu