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

Commit

Permalink
Merge branch 'master' into i/353
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jan 28, 2020
2 parents 1cef183 + e617559 commit 14f856d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/restrictededitingmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export default class RestrictedEditingMode extends Plugin {
* allowedCommands: [ 'bold', 'italic', 'link', 'unlink' ]
* };
*
* To make a command always enabled (also outside non-restricted areas) use
* {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing#enableCommand} method.
*
* @member {Array.<String>} module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig#allowedCommands
*/

Expand Down
23 changes: 21 additions & 2 deletions src/restrictededitingmodeediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
} from './restrictededitingmode/converters';
import { getMarkerAtPosition, isSelectionInMarker } from './restrictededitingmode/utils';

const COMMAND_FORCE_DISABLE_ID = 'RestrictedEditingMode';

/**
* The Restricted Editing Mode editing feature.
*
Expand Down Expand Up @@ -93,6 +95,23 @@ export default class RestrictedEditingModeEditing extends Plugin {
} );
}

/**
* Makes the given command always enabled in the restricted editing mode (regardless
* of selection location).
*
* To enable some commands in non-restricted areas of the content use
* {@link module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig#allowedCommands} configuration option.
*
* @param {String} commandName Name of the command to enable.
*/
enableCommand( commandName ) {
const command = this.editor.commands.get( commandName );

command.clearForceDisabled( COMMAND_FORCE_DISABLE_ID );

this._alwaysEnabled.add( commandName );
}

/**
* Setups restricted mode editing conversion:
*
Expand Down Expand Up @@ -265,7 +284,7 @@ export default class RestrictedEditingModeEditing extends Plugin {
.map( name => editor.commands.get( name ) );

for ( const command of commands ) {
command.clearForceDisabled( 'RestrictedEditingMode' );
command.clearForceDisabled( COMMAND_FORCE_DISABLE_ID );
}
}

Expand All @@ -280,7 +299,7 @@ export default class RestrictedEditingModeEditing extends Plugin {
.map( name => editor.commands.get( name ) );

for ( const command of commands ) {
command.forceDisabled( 'RestrictedEditingMode' );
command.forceDisabled( COMMAND_FORCE_DISABLE_ID );
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/restrictededitingmodeediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import RestrictedEditingModeNavigationCommand from '../src/restrictededitingmode
import ItalicEditing from '@ckeditor/ckeditor5-basic-styles/src/italic/italicediting';
import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';
import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
import Command from '@ckeditor/ckeditor5-core/src/command';

describe( 'RestrictedEditingModeEditing', () => {
let editor, model;
Expand Down Expand Up @@ -63,6 +64,36 @@ describe( 'RestrictedEditingModeEditing', () => {
} );
} );

describe( 'enableCommand()', () => {
let plugin, command;

class FakeCommand extends Command {
refresh() {
this.isEnabled = true;
}
}

beforeEach( async () => {
editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedEditingModeEditing ] } );
model = editor.model;

plugin = editor.plugins.get( RestrictedEditingModeEditing );
command = new FakeCommand( editor );
editor.commands.add( 'fakeCommand', command );

setModelData( editor.model, '<paragraph>[]foo bar baz qux</paragraph>' );
addExceptionMarker( 4, 7, model.document.getRoot().getChild( 0 ) );
} );

it( 'should enable the command globally', () => {
expect( command.isEnabled ).to.be.false;

plugin.enableCommand( 'fakeCommand' );

expect( command.isEnabled ).to.be.true;
} );
} );

describe( 'conversion', () => {
beforeEach( async () => {
editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing, RestrictedEditingModeEditing ] } );
Expand Down

0 comments on commit 14f856d

Please sign in to comment.