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

i/5692: The main editor toolbar should respect the config.toolbar.shouldGroupWhenFull configuration #100

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/classiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export default class ClassicEditor extends Editor {

this.model.document.createRoot();

this.ui = new ClassicEditorUI( this, new ClassicEditorUIView( this.locale, this.editing.view ) );
const shouldToolbarGroupWhenFull = !this.config.get( 'toolbar.shouldNotGroupWhenFull' );
const view = new ClassicEditorUIView( this.locale, this.editing.view, {
shouldToolbarGroupWhenFull
} );

this.ui = new ClassicEditorUI( this, view );

attachToForm( this );
}
Expand Down
8 changes: 6 additions & 2 deletions src/classiceditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export default class ClassicEditorUIView extends BoxedEditorUIView {
*
* @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 {Object} [options={}] Configuration options fo the view instance.
* @param {Boolean} [options.shouldToolbarGroupWhenFull] When set `true` enables automatic items grouping
* in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
* See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
*/
constructor( locale, editingView ) {
constructor( locale, editingView, options = {} ) {
super( locale );

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

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/classiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ describe( 'ClassicEditor', () => {
expect( editor.ui ).to.be.instanceof( ClassicEditorUI );
expect( editor.ui.view ).to.be.instanceof( ClassicEditorUIView );
} );

describe( 'automatic toolbar items groupping', () => {
it( 'should be on by default', () => {
const editorElement = document.createElement( 'div' );
const editor = new ClassicEditor( 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 ClassicEditor( editorElement, {
toolbar: {
shouldNotGroupWhenFull: true
}
} );

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

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

Expand Down
22 changes: 20 additions & 2 deletions tests/classiceditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,26 @@ describe( 'ClassicEditorUIView', () => {
expect( view.stickyPanel.content.get( 0 ) ).to.equal( view.toolbar );
} );

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 ClassicEditorUIView( locale, editingView, {
shouldToolbarGroupWhenFull: true
} );

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

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

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

Expand Down