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

Commit d4f0cc2

Browse files
authored
Merge pull request #78 from ckeditor/t/ckeditor5/488
Other: Align feature class naming to a new scheme.
2 parents 60ac1ab + 76d875b commit d4f0cc2

File tree

8 files changed

+333
-302
lines changed

8 files changed

+333
-302
lines changed

src/undo.js

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
*/
99

1010
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11-
import UndoEngine from './undoengine';
12-
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
13-
14-
import undoIcon from '../theme/icons/undo.svg';
15-
import redoIcon from '../theme/icons/redo.svg';
11+
import UndoEditing from './undoediting';
12+
import UndoUI from './undoui';
1613

1714
/**
18-
* The undo feature. It introduces the Undo and Redo buttons to the editor.
15+
* The undo feature.
16+
*
17+
* It loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
18+
* and {@link module:undo/undoui~UndoUI undo UI feature}.
1919
*
2020
* Below is the explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
2121
*
@@ -106,7 +106,7 @@ export default class Undo extends Plugin {
106106
* @inheritDoc
107107
*/
108108
static get requires() {
109-
return [ UndoEngine ];
109+
return [ UndoEditing, UndoUI ];
110110
}
111111

112112
/**
@@ -115,50 +115,4 @@ export default class Undo extends Plugin {
115115
static get pluginName() {
116116
return 'Undo';
117117
}
118-
119-
/**
120-
* @inheritDoc
121-
*/
122-
init() {
123-
const editor = this.editor;
124-
const t = editor.t;
125-
126-
this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', undoIcon );
127-
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', redoIcon );
128-
129-
editor.keystrokes.set( 'CTRL+Z', 'undo' );
130-
editor.keystrokes.set( 'CTRL+Y', 'redo' );
131-
editor.keystrokes.set( 'CTRL+SHIFT+Z', 'redo' );
132-
}
133-
134-
/**
135-
* Creates a button for the specified command.
136-
*
137-
* @private
138-
* @param {String} name Command name.
139-
* @param {String} label Button label.
140-
* @param {String} keystroke Command keystroke.
141-
* @param {String} Icon Source of the icon.
142-
*/
143-
_addButton( name, label, keystroke, Icon ) {
144-
const editor = this.editor;
145-
const command = editor.commands.get( name );
146-
147-
editor.ui.componentFactory.add( name, locale => {
148-
const view = new ButtonView( locale );
149-
150-
view.set( {
151-
label,
152-
icon: Icon,
153-
keystroke,
154-
tooltip: true
155-
} );
156-
157-
view.bind( 'isEnabled' ).to( command, 'isEnabled' );
158-
159-
this.listenTo( view, 'execute', () => editor.execute( name ) );
160-
161-
return view;
162-
} );
163-
}
164118
}

src/undoengine.js renamed to src/undoediting.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/**
7-
* @module undo/undoengine
7+
* @module undo/undoediting
88
*/
99

1010
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
@@ -19,7 +19,7 @@ import RedoCommand from './redocommand';
1919
*
2020
* @extends module:core/plugin~Plugin
2121
*/
22-
export default class UndoEngine extends Plugin {
22+
export default class UndoEditing extends Plugin {
2323
/**
2424
* @inheritDoc
2525
*/
@@ -31,15 +31,15 @@ export default class UndoEngine extends Plugin {
3131
* Created and registered during the {@link #init feature initialization}.
3232
*
3333
* @private
34-
* @member {undo.UndoEngineCommand} #_undoCommand
34+
* @member {module:undo/undocommand~UndoCommand} #_undoCommand
3535
*/
3636

3737
/**
3838
* The command that manages redo {@link module:engine/model/batch~Batch batches} stack (history).
3939
* Created and registered during the {@link #init feature initialization}.
4040
*
4141
* @private
42-
* @member {undo.UndoEngineCommand} #_redoCommand
42+
* @member {module:undo/undocommand~UndoCommand} #_redoCommand
4343
*/
4444

4545
/**
@@ -55,15 +55,17 @@ export default class UndoEngine extends Plugin {
5555
* @inheritDoc
5656
*/
5757
init() {
58+
const editor = this.editor;
59+
5860
// Create commands.
59-
this._undoCommand = new UndoCommand( this.editor );
60-
this._redoCommand = new RedoCommand( this.editor );
61+
this._undoCommand = new UndoCommand( editor );
62+
this._redoCommand = new RedoCommand( editor );
6163

6264
// Register command to the editor.
63-
this.editor.commands.add( 'undo', this._undoCommand );
64-
this.editor.commands.add( 'redo', this._redoCommand );
65+
editor.commands.add( 'undo', this._undoCommand );
66+
editor.commands.add( 'redo', this._redoCommand );
6567

66-
this.listenTo( this.editor.model, 'applyOperation', ( evt, args ) => {
68+
this.listenTo( editor.model, 'applyOperation', ( evt, args ) => {
6769
const operation = args[ 0 ];
6870

6971
// Do not register batch if the operation is not a document operation.
@@ -99,5 +101,9 @@ export default class UndoEngine extends Plugin {
99101
this.listenTo( this._undoCommand, 'revert', ( evt, undoneBatch, undoingBatch ) => {
100102
this._redoCommand.addBatch( undoingBatch );
101103
} );
104+
105+
editor.keystrokes.set( 'CTRL+Z', 'undo' );
106+
editor.keystrokes.set( 'CTRL+Y', 'redo' );
107+
editor.keystrokes.set( 'CTRL+SHIFT+Z', 'redo' );
102108
}
103109
}

src/undoui.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/**
7+
* @module undo/undoui
8+
*/
9+
10+
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11+
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
12+
13+
import undoIcon from '../theme/icons/undo.svg';
14+
import redoIcon from '../theme/icons/redo.svg';
15+
16+
/**
17+
* The undo UI feature. It introduces the Undo and Redo buttons to the editor.
18+
*
19+
* @extends module:core/plugin~Plugin
20+
*/
21+
export default class UndoUI extends Plugin {
22+
/**
23+
* @inheritDoc
24+
*/
25+
init() {
26+
const editor = this.editor;
27+
const t = editor.t;
28+
29+
this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', undoIcon );
30+
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', redoIcon );
31+
}
32+
33+
/**
34+
* Creates a button for the specified command.
35+
*
36+
* @private
37+
* @param {String} name Command name.
38+
* @param {String} label Button label.
39+
* @param {String} keystroke Command keystroke.
40+
* @param {String} Icon Source of the icon.
41+
*/
42+
_addButton( name, label, keystroke, Icon ) {
43+
const editor = this.editor;
44+
45+
editor.ui.componentFactory.add( name, locale => {
46+
const command = editor.commands.get( name );
47+
const view = new ButtonView( locale );
48+
49+
view.set( {
50+
label,
51+
icon: Icon,
52+
keystroke,
53+
tooltip: true
54+
} );
55+
56+
view.bind( 'isEnabled' ).to( command, 'isEnabled' );
57+
58+
this.listenTo( view, 'execute', () => editor.execute( name ) );
59+
60+
return view;
61+
} );
62+
}
63+
}

tests/undo.js

Lines changed: 6 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,135 +3,16 @@
33
* For licensing, see LICENSE.md.
44
*/
55

6-
/* globals document */
7-
8-
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
96
import Undo from '../src/undo';
10-
import UndoEngine from '../src/undoengine';
11-
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
12-
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
13-
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
14-
15-
testUtils.createSinonSandbox();
7+
import UndoEditing from '../src/undoediting';
8+
import UndoUI from '../src/undoui';
169

1710
describe( 'Undo', () => {
18-
let editor, editorElement;
19-
20-
beforeEach( () => {
21-
editorElement = document.createElement( 'div' );
22-
document.body.appendChild( editorElement );
23-
24-
return ClassicTestEditor.create( editorElement, { plugins: [ Undo ] } )
25-
.then( newEditor => {
26-
editor = newEditor;
27-
} );
28-
} );
29-
30-
afterEach( () => {
31-
editorElement.remove();
32-
33-
return editor.destroy();
34-
} );
35-
36-
it( 'should be loaded', () => {
37-
expect( editor.plugins.get( Undo ) ).to.be.instanceOf( Undo );
38-
} );
39-
40-
it( 'should load UndoEngine', () => {
41-
expect( editor.plugins.get( UndoEngine ) ).to.be.instanceOf( UndoEngine );
42-
} );
43-
44-
testButton( 'undo', 'Undo', 'CTRL+Z' );
45-
testButton( 'redo', 'Redo', 'CTRL+Y' );
46-
47-
it( 'should set CTRL+Z keystroke', () => {
48-
const spy = sinon.stub( editor, 'execute' );
49-
50-
const wasHandled = editor.keystrokes.press( {
51-
keyCode: keyCodes.z,
52-
ctrlKey: true,
53-
preventDefault: sinon.spy(),
54-
stopPropagation: sinon.spy()
55-
} );
56-
57-
expect( wasHandled ).to.be.true;
58-
expect( spy.calledWithExactly( 'undo' ) ).to.be.true;
59-
} );
60-
61-
it( 'should set CTRL+Y keystroke', () => {
62-
const spy = sinon.stub( editor, 'execute' );
63-
64-
const wasHandled = editor.keystrokes.press( {
65-
keyCode: keyCodes.y,
66-
ctrlKey: true,
67-
preventDefault: sinon.spy(),
68-
stopPropagation: sinon.spy()
69-
} );
70-
71-
expect( wasHandled ).to.be.true;
72-
expect( spy.calledWithExactly( 'redo' ) ).to.be.true;
11+
it( 'should be named', () => {
12+
expect( Undo.pluginName ).to.equal( 'Undo' );
7313
} );
7414

75-
it( 'should set CTRL+SHIFT+Z keystroke', () => {
76-
const spy = sinon.stub( editor, 'execute' );
77-
const keyEventData = {
78-
keyCode: keyCodes.z,
79-
ctrlKey: true,
80-
shiftKey: true,
81-
preventDefault: sinon.spy(),
82-
stopPropagation: sinon.spy()
83-
};
84-
85-
const wasHandled = editor.keystrokes.press( keyEventData );
86-
87-
expect( wasHandled ).to.be.true;
88-
expect( spy.calledWithExactly( 'redo' ) ).to.be.true;
89-
expect( keyEventData.preventDefault.calledOnce ).to.be.true;
15+
it( 'should require UndoEditing and UndoUI', () => {
16+
expect( Undo.requires ).to.deep.equal( [ UndoEditing, UndoUI ] );
9017
} );
91-
92-
function testButton( featureName, label, featureKeystroke ) {
93-
describe( `${ featureName } button`, () => {
94-
let button;
95-
96-
beforeEach( () => {
97-
button = editor.ui.componentFactory.create( featureName );
98-
} );
99-
100-
it( 'should register feature component', () => {
101-
expect( button ).to.be.instanceOf( ButtonView );
102-
} );
103-
104-
it( 'should create UI component with correct attribute values', () => {
105-
expect( button.isOn ).to.be.false;
106-
expect( button.label ).to.equal( label );
107-
expect( button.icon ).to.match( /<svg / );
108-
expect( button.keystroke ).to.equal( featureKeystroke );
109-
} );
110-
111-
it( `should execute ${ featureName } command on model execute event`, () => {
112-
const executeSpy = testUtils.sinon.stub( editor, 'execute' );
113-
114-
button.fire( 'execute' );
115-
116-
sinon.assert.calledOnce( executeSpy );
117-
sinon.assert.calledWithExactly( executeSpy, featureName );
118-
} );
119-
120-
it( `should bind model to ${ featureName } command`, () => {
121-
const command = editor.commands.get( featureName );
122-
123-
expect( button.isOn ).to.be.false;
124-
125-
const initState = command.isEnabled;
126-
expect( button.isEnabled ).to.equal( initState );
127-
128-
command.isEnabled = !initState;
129-
expect( button.isEnabled ).to.equal( !initState );
130-
} );
131-
132-
it( 'should set keystroke in the model', () => {
133-
expect( button.keystroke ).to.equal( featureKeystroke );
134-
} );
135-
} );
136-
}
13718
} );

tests/undoengine-integration.js renamed to tests/undoediting-integration.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'
1010
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
1111
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
1212
import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
13-
import UndoEngine from '../src/undoengine';
13+
import UndoEditing from '../src/undoediting';
1414

1515
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
16-
import HeadingEngine from '@ckeditor/ckeditor5-heading/src/headingengine';
16+
import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
1717
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
1818
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
1919
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
20-
import BoldEngine from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
20+
import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
2121

2222
import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
2323
import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
2424

2525
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
2626

27-
describe( 'UndoEngine integration', () => {
27+
describe( 'UndoEditing integration', () => {
2828
let editor, model, doc, root, div;
2929

3030
beforeEach( () => {
3131
div = document.createElement( 'div' );
3232
document.body.appendChild( div );
3333

34-
return ClassicEditor.create( div, { plugins: [ Paragraph, HeadingEngine, Typing, Enter, Clipboard, BoldEngine, UndoEngine ] } )
34+
return ClassicEditor.create( div, { plugins: [ Paragraph, HeadingEditing, Typing, Enter, Clipboard, BoldEditing, UndoEditing ] } )
3535
.then( newEditor => {
3636
editor = newEditor;
3737

0 commit comments

Comments
 (0)