Forum closed. New forum available at http://community.wymeditor.org/

How to change bahaviour enter/backspace pressed

Support forum for WYMeditor.

How to change bahaviour enter/backspace pressed

Postby liysd on Thu Apr 22, 2010 5:21 pm

Hi all,

In Google Chrome after pressing enter key in WYMEDITOR a new <p> is created. How to change it? I would rather insert <br /> tag as it happens after shift-enter combination. (In fact shif-enter creates two <br />).

Similar question concerns backspace pressed on the beginning of paragraph. How to change this behaviour to erase paragraph (or other) only when it is empty and do nothing otherwise.

I'll be greatful for any hints.

Krzysztof Liysd
liysd
 
Posts: 7
Joined: Thu Apr 22, 2010 5:07 pm

Re: How to change bahaviour enter/backspace pressed

Postby mr_lundis on Sat Apr 24, 2010 8:43 pm

One of the main ideas with WYMeditor is to more or less force a good document structure. Using line breaks to separate text in to paragraphs is not good. With that said, take a look at the different key related event handlers if you want to change this behavior - although most browsers create new paragraphs by default when pressing enter inside an existing paragraph. The event.preventDefault method might stop that. The double line breaks when using shift-enter is a known webkit bug.

Regarding your other question, I'm not sure I understand what you want to do. Could you please clarify?

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: How to change bahaviour enter/backspace pressed

Postby liysd on Mon Apr 26, 2010 10:51 am

I want to add some containers with slightly other behaviour than <p>. For example in my app tags <p class="example"> some text </p> after edition will be transformed (with use of xslt schema) to <example> some text </example> and therefore I would like to have a oportunity to easily enter text containing <br />s. New containers are created by buttons from menu.

Regarding the other question, normally when I press backspace at the beginning of container WYMeditor deletes this container and moves its content to the previous one. The only exception is with the first container. When the caret is at the begining of container I would like to have behaviour like this:
1. If container is not empty - do nothing
2. If container is empty - remove container.

Similarly when delete is pressed at the end of container. I don't want to have content of the next container moved to the previous one.

It is also because I've noticed some incorrect behaviour when a content is moved between containers, especially when some other tags are used.
liysd
 
Posts: 7
Joined: Thu Apr 22, 2010 5:07 pm

Re: How to change bahaviour enter/backspace pressed

Postby mr_lundis on Sun May 16, 2010 11:56 am

Okay, I understand. What you'll have to do is to listen to the keydown event inside the iframe and prevent the default action when backspace is pressed and the caret is at the beginning of the element or when delete is pressed and the carets at the end. I'd recommend wrapping it all up in a plug-in.

Some resources:

Key events:
http://www.quirksmode.org/js/keys.html

Selections in W3C compliant browsers:
https://developer.mozilla.org/En/DOM/Range
https://developer.mozilla.org/en/DOM/Selection

Selections in IE (before IE9):
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests