8
0
Просмотр исходного кода

Integrated List feature with the KeystrokeHandler.

Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
78cd5ac096
1 измененных файлов с 9 добавлено и 19 удалено
  1. 9 19
      packages/ckeditor5-list/src/list.js

+ 9 - 19
packages/ckeditor5-list/src/list.js

@@ -13,7 +13,6 @@ import numberedListIcon from '../theme/icons/numberedlist.svg';
 import bulletedListIcon from '../theme/icons/bulletedlist.svg';
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { parseKeystroke } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 
 /**
@@ -62,29 +61,20 @@ export default class List extends Plugin {
 			}
 		} );
 
-		// Add Tab key support.
-		// When in list item, pressing Tab should indent list item, if possible.
-		// Pressing Shift+Tab should outdent list item.
-		this.listenTo( this.editor.editing.view, 'keydown', ( evt, data ) => {
-			let commandName;
-
-			if ( data.keystroke == parseKeystroke( 'Tab' ) ) {
-				commandName = 'indentList';
-			} else if ( data.keystroke == parseKeystroke( 'Shift+Tab' ) ) {
-				commandName = 'outdentList';
-			}
-
-			if ( commandName ) {
+		const getCommandExecuter = commandName => {
+			return ( data, cancel ) => {
 				const command = this.editor.commands.get( commandName );
 
 				if ( command.isEnabled ) {
 					this.editor.execute( commandName );
-
-					data.preventDefault();
-					evt.stop();
 				}
-			}
-		} );
+
+				cancel();
+			};
+		};
+
+		this.editor.keystrokes.set( 'Tab', getCommandExecuter( 'indentList' ) );
+		this.editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentList' ) );
 	}
 
 	/**