|
@@ -11,6 +11,53 @@ import ArticlePluginSet from '../_utils/articlepluginset';
|
|
|
import MultiCommand from '../../src/multicommand';
|
|
import MultiCommand from '../../src/multicommand';
|
|
|
import Plugin from '../../src/plugin';
|
|
import Plugin from '../../src/plugin';
|
|
|
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
|
|
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
|
|
|
|
|
+import Command from '../../src/command';
|
|
|
|
|
+import first from '@ckeditor/ckeditor5-utils/src/first';
|
|
|
|
|
+
|
|
|
|
|
+class IndentBlockCommand extends Command {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritDoc
|
|
|
|
|
+ */
|
|
|
|
|
+ refresh() {
|
|
|
|
|
+ this.isEnabled = this._checkEnabled();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Indents or outdents (depends on the {@link #constructor}'s `indentDirection` parameter) selected list items.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @fires execute
|
|
|
|
|
+ */
|
|
|
|
|
+ execute() {
|
|
|
|
|
+ const model = this.editor.model;
|
|
|
|
|
+ const doc = model.document;
|
|
|
|
|
+
|
|
|
|
|
+ const itemsToChange = Array.from( doc.selection.getSelectedBlocks() );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( () => {
|
|
|
|
|
+ for ( const item of itemsToChange ) {
|
|
|
|
|
+ console.log( 'indent block', item );
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Checks whether the command can be enabled in the current context.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @returns {Boolean} Whether the command should be enabled.
|
|
|
|
|
+ */
|
|
|
|
|
+ _checkEnabled() {
|
|
|
|
|
+ // Check whether any of position's ancestor is a list item.
|
|
|
|
|
+ const block = first( this.editor.model.document.selection.getSelectedBlocks() );
|
|
|
|
|
+
|
|
|
|
|
+ // If selection is not in a list item, the command is disabled.
|
|
|
|
|
+ if ( !block || !this.editor.model.schema.checkAttribute( block, 'indent' ) ) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
class IndentOutdent extends Plugin {
|
|
class IndentOutdent extends Plugin {
|
|
|
init() {
|
|
init() {
|
|
@@ -18,7 +65,11 @@ class IndentOutdent extends Plugin {
|
|
|
const t = editor.t;
|
|
const t = editor.t;
|
|
|
|
|
|
|
|
this._createButton( 'indent', t( 'Indent' ) );
|
|
this._createButton( 'indent', t( 'Indent' ) );
|
|
|
- this._createButton( 'outdent', t( 'Outdent' ) );
|
|
|
|
|
|
|
+ // this._createButton( 'outdent', t( 'Outdent' ) );
|
|
|
|
|
+ this._createButton( 'indentList', t( 'Indent List' ) );
|
|
|
|
|
+ // this._createButton( 'outdentList', t( 'Outdent List' ) );
|
|
|
|
|
+ this._createButton( 'indentBlock', t( 'Indent Block' ) );
|
|
|
|
|
+ // this._createButton( 'outdentBlock', t( 'Outdent Block' ) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_createButton( commandName, label ) {
|
|
_createButton( commandName, label ) {
|
|
@@ -46,10 +97,20 @@ class IndentOutdent extends Plugin {
|
|
|
afterInit() {
|
|
afterInit() {
|
|
|
const editor = this.editor;
|
|
const editor = this.editor;
|
|
|
|
|
|
|
|
|
|
+ editor.commands.add( 'indentBlock', new IndentBlockCommand( editor ) );
|
|
|
|
|
+
|
|
|
const indentCommand = new MultiCommand( editor );
|
|
const indentCommand = new MultiCommand( editor );
|
|
|
|
|
+
|
|
|
indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) );
|
|
indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) );
|
|
|
|
|
+ indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
|
|
|
|
|
+
|
|
|
editor.commands.add( 'indent', indentCommand );
|
|
editor.commands.add( 'indent', indentCommand );
|
|
|
|
|
|
|
|
|
|
+ // TODO nicer API?
|
|
|
|
|
+ // editor.commands.add( 'indentList', new Command(), 'indent' );
|
|
|
|
|
+ // editor.commands.addMulti( 'indentList', new Command(), 'indent' );
|
|
|
|
|
+ // editor.commands.addMulti( 'indentList', 'indent' );
|
|
|
|
|
+
|
|
|
const outdentCommand = new MultiCommand( editor );
|
|
const outdentCommand = new MultiCommand( editor );
|
|
|
outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) );
|
|
outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) );
|
|
|
editor.commands.add( 'outdent', outdentCommand );
|
|
editor.commands.add( 'outdent', outdentCommand );
|
|
@@ -97,20 +158,26 @@ ClassicEditor
|
|
|
plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ],
|
|
plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ],
|
|
|
toolbar: [
|
|
toolbar: [
|
|
|
'heading',
|
|
'heading',
|
|
|
- '|',
|
|
|
|
|
- 'bold',
|
|
|
|
|
- 'italic',
|
|
|
|
|
- 'link',
|
|
|
|
|
|
|
+ // '|',
|
|
|
|
|
+ // 'bold',
|
|
|
|
|
+ // 'italic',
|
|
|
|
|
+ // 'link',
|
|
|
'|',
|
|
'|',
|
|
|
'indent',
|
|
'indent',
|
|
|
'outdent',
|
|
'outdent',
|
|
|
'|',
|
|
'|',
|
|
|
|
|
+ 'indentList',
|
|
|
|
|
+ 'outdentList',
|
|
|
|
|
+ '|',
|
|
|
|
|
+ 'indentBlock',
|
|
|
|
|
+ 'outdentBlock',
|
|
|
|
|
+ '|',
|
|
|
'bulletedList',
|
|
'bulletedList',
|
|
|
'numberedList',
|
|
'numberedList',
|
|
|
'|',
|
|
'|',
|
|
|
- 'blockQuote',
|
|
|
|
|
- 'insertTable',
|
|
|
|
|
- 'mediaEmbed',
|
|
|
|
|
|
|
+ // 'blockQuote',
|
|
|
|
|
+ // 'insertTable',
|
|
|
|
|
+ // 'mediaEmbed',
|
|
|
'undo',
|
|
'undo',
|
|
|
'redo'
|
|
'redo'
|
|
|
],
|
|
],
|