htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
Solution for <p> and <br>(double space)problem


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


S. Lim
New User

Nov 26, 2003, 6:41 AM

Post #1 of 12 (6613 views)
Shortcut
Solution for <p> and <br>(double space)problem Can't Post

Hi there,
I've read a lot of discussions on how to solve double space
(<p> instead of <br>) problem.
I've extended the solution that some other suggest.

Here it is:

Code
 function OnKeyDown()   
{
switch ( event.keyCode )
{
case 13:
if ( !( document.queryCommandState( 'insertorderedlist' )
|| document.queryCommandState( 'insertunorderedlist' ) )
&& event.shiftKey == false )
{
var range = document.selection.createRange();
range.pasteHTML( '<br />' );
event.cancelBubble = true;
event.returnValue = false;

range.select();
range.move('character',1);
return false;
}
break;
}
return true;
}

Use this function as your onkeydown event and voila, the requested behavior. If you have more exception (like insertorderedlist) situations, you probably can add it to the if expression. Hope some of you can use this code.Cool


tru
New User

Nov 26, 2003, 9:28 PM

Post #2 of 12 (6574 views)
Shortcut
Re: [S. Lim] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Sounds great. Can you give an example of how to install the onkeydown function? I'm using two versions of htmlarea: (1) ver 3.0 beta for Mozilla browsers and Luis' version for IE windows users.

Thanks! Smile


WeeZard
Novice

Nov 30, 2003, 6:00 AM

Post #3 of 12 (6523 views)
Shortcut
Re: [tru] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

search for

Code
	else if (keyEvent) { 
// other keys here

@ switch (ev.KeyCode) { ##here## }
enter this

Code
      case 13:    
if ( !( document.queryCommandState( 'insertorderedlist' )
|| document.queryCommandState( 'insertunorderedlist' ) )
&& ev.shiftKey == false )
{
var range = document.selection.createRange();
range.pasteHTML( '<br />' );
ev.cancelBubble = true;
ev.returnValue = false;

range.select();
range.move('character',1);
return false;
}
break;



Denver Dave
User

Dec 9, 2003, 10:11 AM

Post #4 of 12 (6389 views)
Shortcut
Re: [S. Lim] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Thanks. Is there anyone that does not want this fix to be the default behavior?


Aspirinho
New User

Dec 9, 2003, 10:21 AM

Post #5 of 12 (6386 views)
Shortcut
Re: [Denver Dave] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Thanks for this piece of code! I had the problem, that I want <p>s to be inserted even in Mozilla when enter is pressed, so I might turnaround your code ;-)


vtsuper
Novice

Dec 10, 2003, 6:08 AM

Post #6 of 12 (6365 views)
Shortcut
Re: [S. Lim] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

can I use this method in htmlArea version 2?


Hipikat
User

Jan 19, 2004, 7:12 PM

Post #7 of 12 (6119 views)
Shortcut
Re: [Aspirinho] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

I'm also trying to make <P> the default behaviour in all browsers. Has anyone achieved this?

I'm having issues with Mozilla warping insertHTML'd into crazy things like </P><P /><P>, which confuses the wysiwyg editor to no end...


rehab_shouman
Novice

Jan 29, 2004, 5:09 AM

Post #8 of 12 (6023 views)
Shortcut
Re: [WeeZard] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

i still have the space problem....i used ur code, but when i have spaced in my textarea and i make spell check like:"hi thr" i get this is the spell check window : "hiž/span> ? thr"

i have no idea whats wrong?!


Hipikat
User

Feb 3, 2004, 2:41 AM

Post #9 of 12 (5950 views)
Shortcut
Re: [Hipikat] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

(This topic is also being dealt with in http://www.interactivetools.com/forum/gforum.cgi?post=23132#23132...)

Well, it's a lot of extra code, but I've finally done it :) For anyone desperate for Mozilla to perform proper behavior upon enter, behold my attachment. For anyone unfamiliar with the intricacies of running patch, there's a htmlarea.js also attached - but you'd better run it with a htmlArea directory from a similar era to today.

It involved a lot of DOM work. It's been fairly thoroughly tested. It's actually quite an interesting hack...

The patch is up against a htmlArea taken from the CVS about ten minutes ago.

Please, please please, if anyone finds any bugs with it, send them to me. On the other hand, it's about to be unleashed on my University, so I'll probably get enough local bug reports :P


(This post was edited by Hipikat on Feb 4, 2004, 8:01 PM)
Attachments: fixparas040203.diff (9.94 KB)
  htmlarea.js.fixpara01 (74.0 KB)


ferobert
New User

May 26, 2004, 7:46 AM

Post #10 of 12 (5263 views)
Shortcut
Re: [S. Lim] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Hello,

I am trying to achieve the <Enter> = <br> effect in IE, and incorporated the 2 suggested code snippets. In both cases, the end result is OK, but visually may confuse users, as after pressing <Enter>, the cursor stays on the same line (moves to the left a bit). Only after the user presses another key, the cursor goes down one line. Seems that others also have experienced this problem, so it's not just my IE (version 6.0):

http://www.interactivetools.com/forum/gforum.cgi?post=16998

Is there any solution for this issue?

Thanks and regards
Robert


Chuck
Novice

Dec 21, 2004, 1:43 PM

Post #11 of 12 (4442 views)
Shortcut
Re: [ferobert] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Has this been fixed in any ways?

I changed my code to do only "br"s instead in "p"s in internet explorer and I also have that same problem where the cursor stays on the same line, a bit to the right, until some other key is pressed, which, as the other post said, is a bit confusing for our users.

Thanks in advance for your replies

(It's also IE 6 which causes all of this)


Chuck
Novice

Jan 4, 2005, 9:21 AM

Post #12 of 12 (4240 views)
Shortcut
Re: [Chuck] Solution for <p> and <br>(double space)problem [In reply to] Can't Post

Well, after further testing, my solutions seems to create another problem as, it looks like it's impossible to create lists with that part of code enabled, pressing ENTER in a list only seems to create line breaks inside the first list item instead of making a new item.

I haven't found a fix for this yet. Has anyone found a better solution?

 
 
 


Search for (options)