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

Commit

Permalink
Merge pull request #45 from ckeditor/i/5692
Browse files Browse the repository at this point in the history
Feature: The main editor toolbar should respect the `config.toolbar.shouldNotGroupWhenFull` configuration (see ckeditor/ckeditor5#5692).
  • Loading branch information
Reinmar authored Nov 20, 2019
2 parents a04e08c + 6eb6442 commit 35b3cbf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export default class DecoupledEditor extends Editor {

this.model.document.createRoot();

const view = new DecoupledEditorUIView( this.locale, this.editing.view, this.sourceElement );
const shouldToolbarGroupWhenFull = !this.config.get( 'toolbar.shouldNotGroupWhenFull' );
const view = new DecoupledEditorUIView( this.locale, this.editing.view, {
editableElement: this.sourceElement,
shouldToolbarGroupWhenFull
} );

this.ui = new DecoupledEditorUI( this, view );
}

Expand Down
12 changes: 8 additions & 4 deletions src/decouplededitoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ export default class DecoupledEditorUIView extends EditorUIView {
*
* @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
* @param {module:engine/view/view~View} editingView The editing view instance this view is related to.
* @param {HTMLElement} [editableElement] The editable element. If not specified, it will be automatically created by
* @param {Object} [options={}] Configuration options fo the view instance.
* @param {HTMLElement} [options.editableElement] The editable element. If not specified, it will be automatically created by
* {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
* @param {Boolean} [options.shouldToolbarGroupWhenFull] When set `true` enables automatic items grouping
* in the main {@link editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
* See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
*/
constructor( locale, editingView, editableElement ) {
constructor( locale, editingView, options = {} ) {
super( locale );

/**
Expand All @@ -41,7 +45,7 @@ export default class DecoupledEditorUIView extends EditorUIView {
* @member {module:ui/toolbar/toolbarview~ToolbarView}
*/
this.toolbar = new ToolbarView( locale, {
shouldGroupWhenFull: true
shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
} );

/**
Expand All @@ -50,7 +54,7 @@ export default class DecoupledEditorUIView extends EditorUIView {
* @readonly
* @member {module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView}
*/
this.editable = new InlineEditableUIView( locale, editingView, editableElement );
this.editable = new InlineEditableUIView( locale, editingView, options.editableElement );

// This toolbar may be placed anywhere in the page so things like font size need to be reset in it.
// Because of the above, make sure the toolbar supports rounded corners.
Expand Down
24 changes: 24 additions & 0 deletions tests/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ describe( 'DecoupledEditor', () => {

editor.ui.destroy();
} );

describe( 'automatic toolbar items groupping', () => {
it( 'should be on by default', () => {
const editorElement = document.createElement( 'div' );
const editor = new DecoupledEditor( editorElement );

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.true;

editorElement.remove();
} );

it( 'can be disabled using config.toolbar.shouldNotGroupWhenFull', () => {
const editorElement = document.createElement( 'div' );
const editor = new DecoupledEditor( editorElement, {
toolbar: {
shouldNotGroupWhenFull: true
}
} );

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.false;

editorElement.remove();
} );
} );
} );
} );

Expand Down
26 changes: 23 additions & 3 deletions tests/decouplededitoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,26 @@ describe( 'DecoupledEditorUIView', () => {
expect( view.toolbar.isRendered ).to.be.false;
} );

it( 'has automatic items grouping enabled', () => {
expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;
describe( 'automatic items grouping', () => {
it( 'should be disabled by default', () => {
expect( view.toolbar.options.shouldGroupWhenFull ).to.be.undefined;
} );

it( 'should be controlled via options.shouldToolbarGroupWhenFull', () => {
const locale = new Locale();
const editingView = new EditingView();
const editingViewRoot = createRoot( editingView.document );
const view = new DecoupledEditorUIView( locale, editingView, {
shouldToolbarGroupWhenFull: true
} );

view.editable.name = editingViewRoot.rootName;
view.render();

expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;

return view.destroy();
} );
} );
} );

Expand All @@ -66,7 +84,9 @@ describe( 'DecoupledEditorUIView', () => {

it( 'can be created out of an existing DOM element', () => {
const editableElement = document.createElement( 'div' );
const testView = new DecoupledEditorUIView( locale, editingView, editableElement );
const testView = new DecoupledEditorUIView( locale, editingView, {
editableElement
} );
testView.editable.name = editingViewRoot.rootName;

testView.render();
Expand Down

0 comments on commit 35b3cbf

Please sign in to comment.