Opened 14 years ago
Last modified 12 years ago
#7836 confirmed Bug
In Firefox, a <br /> is inserted in an empty text area when using editor.focus() on initially hidden editors
Reported by: | Niek Kouwenberg | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | General | Version: | 3.3 |
Keywords: | Firefox | Cc: |
Description
In our CMS, the CKEditor is sometimes loaded in the background, in a hidden div (part of a tabset). Although hidden, the editor instance is already created and works fine.
When displaying the DIV, I want to focus the editor, and do so by using editor.focus(). This will put focus on the editor. This works correctly for and empty editor or one with content, and works correctly in all browsers.
The only exception is Firefox (tested on both version 3 and 4), which adds the following content on a editor without any content:
<p><br /> </p>
The result being an empty editor, with a <br /> tag in it. In addition, focus is placed on the second line, but when starting to type it will place all text on the first line, NOT removing the second line. You just can't type anything on the second line.
This issue has been present since at least 3.5.3.
Steps to reproduce:
- Create a DIV with display: none;
- Place a textarea inside, without any content
- Replace the textarea with a CKEditor
- Show the DIV (it will not have focus)
- Focus the editor using editor.focus()
- The code mentioned above is inserted into the editor
Expected result:
- The editor is focused, content remains empty
Does not apply for:
- other browsers than Firefox
- editor with existing content
- manually focusing the editor by clicking on it
- editors not hidden when created
Attachments (2)
Change History (6)
Changed 14 years ago by
Attachment: | focus_issue.html added |
---|
comment:1 Changed 14 years ago by
Keywords: | Firefox added |
---|---|
Status: | new → confirmed |
Version: | 3.6 → 3.3.2 |
Reproducible on Firefox browsers in Windows XP (in Win 7 it works fine).
This is rather strange issue. I have tried to replicate it using:
<p id="editor3_container" style="display:none;"> <textarea cols="80" id="editor3" name="editor3" rows="10"></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor3' ); document.getElementById('editor3_container').style.display = ''; setTimeout(function(){CKEDITOR.instances['editor3'].focus()}, 3000); </script> </p>
and then:
<p id="editor3_container" style="display:none;"> <textarea cols="80" id="editor3" name="editor3" rows="10"></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor3' ); document.getElementById('editor3_container').style.display = ''; </script> <br/> <input type="button" onclick="CKEDITOR.instances['editor3'].focus();" value="focus2" /> </p>
None of this resulted in error.
Br tags were inserted only when to buttons with inline events were used - one for showing editor and the other for setting the focus.
comment:2 Changed 14 years ago by
My original code doesn't use two separate buttons, but an Ajax response to load the editor and a onclick event listener to show the hidden tab and focus the editor afterwards. Long timeouts between all actions make no difference. The problem should therefore not be search for in the buttons with onclick actions.
P.S. I am using Windows 7, so the problem occurs there too.
comment:3 Changed 14 years ago by
Confirmed with FF4 and Windows 7 with the provided TC page.
I've checked the DOM with Firebug. As soonas we click the "show" button, the editing area contains the following:
<br type="_moz">
Then, when clicking on "focus", the editor automatically fixes the above structure, by creating a <p> for it. Problem is that we now have two padding <br>s:
<p><br type="_moz"><br type="_moz"></p>
This breaks things, as we should not have this additional padding <br> created.
Changed 12 years ago by
comment:4 Changed 12 years ago by
Version: | 3.3.2 → 3.3 |
---|
It seems that there is easier way to reproduce this problem.
- Paste the below code into any sample or use abc3.html attached to this ticket
editor.on('instanceReady', function(e){ e.editor.on('afterSetData', function(evt){ e.editor.focus(); }); e.editor.setData('<p>Some text</p><p> </p>'); });
- Once data is set, start typing - you will see that br is added above typed text.
Problem has been reproducible in all Operating Systems from CKEditor 3.3.
NOTES:
- There is no need for using hidden div.
- It seems that this problem only occurs with empty lines. When using in setData E.g.
e.editor.setData('<p>Some text</p>');
there is no problem.
Test case (copied from _samples) displaying the odd behavior.