8
0
Quellcode durchsuchen

Implemented tooltips with keystroke information next to Undo and Redo buttons.

Aleksander Nowodzinski vor 9 Jahren
Ursprung
Commit
aa7f1f2969
2 geänderte Dateien mit 14 neuen und 8 gelöschten Zeilen
  1. 7 5
      packages/ckeditor5-undo/src/undo.js
  2. 7 3
      packages/ckeditor5-undo/tests/undo.js

+ 7 - 5
packages/ckeditor5-undo/src/undo.js

@@ -65,7 +65,7 @@ import ButtonView from '../ui/button/buttonview.js';
  * delta is undone or reversed, it is "removed" and there should be no sign of it in the history (fig. 1).
  *
  * Notes:
- * 
+ *
  * * `---` symbolizes a removed delta.
  * * `'` symbolizes a reversed delta that was later transformed.
  *
@@ -136,8 +136,8 @@ export default class Undo extends Feature {
 		const editor = this.editor;
 		const t = editor.t;
 
-		this._addButton( 'undo', t( 'Undo' ) );
-		this._addButton( 'redo', t( 'Redo' ) );
+		this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z' );
+		this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y' );
 
 		editor.keystrokes.set( 'CTRL+Z', 'undo' );
 		editor.keystrokes.set( 'CTRL+Y', 'redo' );
@@ -150,8 +150,9 @@ export default class Undo extends Feature {
 	 * @private
 	 * @param {String} name Command name.
 	 * @param {String} label Button label.
+	 * @param {String} keystroke Command keystroke.
 	 */
-	_addButton( name, label ) {
+	_addButton( name, label, keystroke ) {
 		const editor = this.editor;
 
 		const command = editor.commands.get( name );
@@ -159,7 +160,8 @@ export default class Undo extends Feature {
 		const model = new Model( {
 			isOn: false,
 			label: label,
-			icon: name
+			icon: name,
+			keystroke
 		} );
 
 		model.bind( 'isEnabled' ).to( command, 'isEnabled' );

+ 7 - 3
packages/ckeditor5-undo/tests/undo.js

@@ -36,8 +36,8 @@ describe( 'Undo', () => {
 		expect( editor.plugins.get( UndoEngine ) ).to.be.instanceOf( UndoEngine );
 	} );
 
-	testButton( 'undo' );
-	testButton( 'redo' );
+	testButton( 'undo', 'CTRL+Z' );
+	testButton( 'redo', 'CTRL+Y' );
 
 	it( 'should set CTRL+Z keystroke', () => {
 		const spy = sinon.stub( editor, 'execute' );
@@ -66,7 +66,7 @@ describe( 'Undo', () => {
 		expect( spy.calledWithExactly( 'redo' ) ).to.be.true;
 	} );
 
-	function testButton( featureName ) {
+	function testButton( featureName, featureKeystroke ) {
 		describe( `${ featureName } button`, () => {
 			let buttonController;
 
@@ -100,6 +100,10 @@ describe( 'Undo', () => {
 				command.isEnabled = !initState;
 				expect( model.isEnabled ).to.equal( !initState );
 			} );
+
+			it( 'should set keystroke in the model', () => {
+				expect( buttonController.model.keystroke ).to.equal( featureKeystroke );
+			} );
 		} );
 	}
 } );