Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 4b7d435

Browse files
authored
Merge pull request #1244 from ckeditor/t/ckeditor5/721
Fix: Fixed a bug where Firefox would throw an `NS_ERROR_FAILURE` error when moving selection from a nested editable to the root editable. Closes ckeditor/ckeditor5#721.
2 parents fd128a1 + 3b2737e commit 4b7d435

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

src/view/renderer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,10 @@ export default class Renderer {
628628
const anchor = this.domConverter.viewPositionToDom( this.selection.anchor );
629629
const focus = this.domConverter.viewPositionToDom( this.selection.focus );
630630

631+
// Focus the new editing host.
632+
// Otherwise, FF may throw an error (https://github.com/ckeditor/ckeditor5/issues/721).
633+
domRoot.focus();
634+
631635
domSelection.collapse( anchor.parent, anchor.offset );
632636
domSelection.extend( focus.parent, focus.offset );
633637
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<style>
2+
.ck-widget {
3+
border: solid 3px blue;
4+
}
5+
</style>
6+
7+
<div id="editor">
8+
<p>This is an <strong>editor</strong> instance.</p>
9+
</div>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* globals console, window, document */
7+
8+
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
9+
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
10+
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
11+
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
12+
import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';
13+
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
14+
15+
import AttributeContainer from '../../../../src/view/attributeelement';
16+
import ViewContainer from '../../../../src/view/containerelement';
17+
import { downcastElementToElement } from '../../../../src/conversion/downcast-converters';
18+
import { setData } from '../../../../src/dev-utils/model';
19+
import ViewEditable from '../../../../src/view/editableelement';
20+
21+
ClassicEditor
22+
.create( document.querySelector( '#editor' ), {
23+
plugins: [ Essentials, Paragraph, Bold, Widget ],
24+
toolbar: [ 'undo', 'redo' ]
25+
} )
26+
.then( editor => {
27+
window.editor = editor;
28+
29+
const model = editor.model;
30+
31+
model.schema.register( 'widget', {
32+
inheritAllFrom: '$block',
33+
isObject: true
34+
} );
35+
36+
model.schema.extend( '$text', {
37+
allowIn: 'nested'
38+
} );
39+
40+
model.schema.register( 'nested', {
41+
allowIn: 'widget',
42+
isLimit: true
43+
} );
44+
45+
editor.conversion.for( 'downcast' )
46+
.add( downcastElementToElement( {
47+
model: 'widget',
48+
view: () => {
49+
const b = new AttributeContainer( 'b' );
50+
const div = new ViewContainer( 'div', null, b );
51+
52+
return toWidget( div, { label: 'element label' } );
53+
}
54+
} ) )
55+
.add( downcastElementToElement( {
56+
model: 'nested',
57+
view: () => new ViewEditable( 'figcaption', { contenteditable: true } )
58+
} ) );
59+
60+
setData( editor.model,
61+
'<paragraph>foo[]</paragraph>' +
62+
'<widget><nested>bar</nested></widget>' +
63+
'<widget><nested>bom</nested></widget>'
64+
);
65+
} )
66+
.catch( err => {
67+
console.error( err.stack );
68+
} );
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Renderer should handle nested editables [FF] <a href="https://github.com/ckeditor/ckeditor5/issues/721">ckeditor5#721</a>
2+
3+
### TC1
4+
5+
1. Put the caret in the first paragraph and type something.
6+
1. Put the caret inside the widget (in "bar").
7+
1. Click "Undo" or press <kbd>Ctrl</kbd>+<kbd>Z</kbd> (check both).
8+
9+
**Expected**:
10+
11+
No error in the console.
12+
13+
### TC2
14+
15+
Try the same TC as above but use both nested editables. See if the focus is correctly moved between them.
16+

0 commit comments

Comments
 (0)