File: keystrokehandler.js

package info (click to toggle)
ckeditor 4.4.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,632 kB
  • ctags: 2,419
  • sloc: sh: 190; python: 37; makefile: 29; php: 15; xml: 5
file content (64 lines) | stat: -rw-r--r-- 1,602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* bender-tags: editor,unit */

CKEDITOR.replaceClass = 'ckeditor';
bender.editor = true;

var keyCombo1 = CKEDITOR.CTRL + 10,
	keyCombo2 = CKEDITOR.ALT + 20,
	command1 = 'command#1',
	command2 = 'command#2',
	command3 = 'command#3';

function clearStrokes( keystrokes ) {
	delete keystrokes[ keyCombo1 ];
	delete keystrokes[ keyCombo2 ];
}

bender.test(
{
	'test keystroke assignment' : function() {
		var editor = this.editor,
			keystrokes = editor.keystrokeHandler.keystrokes;

		clearStrokes( keystrokes );

		editor.setKeystroke( keyCombo1, command1 );
		assert.areEqual( command1, keystrokes[ keyCombo1 ] );
	},

	'test keystroke array assignment' : function() {
		var editor = this.editor,
			keystrokes = editor.keystrokeHandler.keystrokes;

		clearStrokes( keystrokes );

		editor.setKeystroke(
		[
			[ keyCombo1, command1 ],
			[ keyCombo2, command2 ],
		] );

		assert.areEqual( command1, keystrokes[ keyCombo1 ] );
		assert.areEqual( command2, keystrokes[ keyCombo2 ] );
	},

	'test editor#key event': function() {
		var fired = 0,
			evtData = null,
			listener = this.editor.on( 'key', function( evt ) {
				fired += 1;
				evtData = evt.data;
			} );

		this.editor.editable().fire( 'keydown', new CKEDITOR.dom.event( {
			keyCode: 66,
			ctrlKey: true,
			shiftKey: true
		} ) );

		assert.areSame( 1, fired, 'editor#key has been fired once' );
		assert.areSame( CKEDITOR.CTRL + CKEDITOR.SHIFT + 66, evtData.keyCode, 'keyCode' );
		assert.isInstanceOf( CKEDITOR.dom.event, evtData.domEvent, 'domEvent' );
		assert.areSame( 66, evtData.domEvent.getKey(), 'domEvent.getKey()' );
	}
} );