@@ -9,9 +9,53 @@ import { TPromise } from 'vs/base/common/winjs.base';
99import { IDisposable } from 'vs/base/common/lifecycle' ;
1010import { IWindowDriver , IElement , WindowDriverChannel , WindowDriverRegistryChannelClient } from 'vs/platform/driver/common/driver' ;
1111import { IPCClient } from 'vs/base/parts/ipc/common/ipc' ;
12+ import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO' ;
13+ import { SimpleKeybinding } from 'vs/base/common/keyCodes' ;
14+ import { ScanCodeBinding , IMMUTABLE_KEY_CODE_TO_CODE , ScanCodeUtils } from 'vs/workbench/services/keybinding/common/scanCode' ;
15+ import { IKeybindingService , IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding' ;
16+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1217
1318class WindowDriver implements IWindowDriver {
1419
20+ constructor (
21+ @IKeybindingService private keybindingService : IKeybindingService
22+ ) { }
23+
24+ async dispatchKeybinding ( rawKeybinding : string ) : TPromise < void > {
25+ const [ first , second ] = KeybindingIO . _readUserBinding ( rawKeybinding ) ;
26+
27+ this . _dispatchKeybinding ( first ) ;
28+
29+ if ( second ) {
30+ this . _dispatchKeybinding ( second ) ;
31+ }
32+ }
33+
34+ private _dispatchKeybinding ( keybinding : SimpleKeybinding | ScanCodeBinding ) : void {
35+ if ( keybinding instanceof ScanCodeBinding ) {
36+ throw new Error ( 'ScanCodeBindings not supported' ) ;
37+ }
38+
39+ const scanCode = IMMUTABLE_KEY_CODE_TO_CODE [ keybinding . keyCode ] ;
40+ const event : IKeyboardEvent = {
41+ ctrlKey : keybinding . ctrlKey ,
42+ altKey : keybinding . altKey ,
43+ shiftKey : keybinding . shiftKey ,
44+ metaKey : keybinding . metaKey ,
45+ keyCode : keybinding . keyCode ,
46+ code : ScanCodeUtils . toString ( scanCode )
47+ } ;
48+
49+ this . keybindingService . dispatchEvent ( event , document . activeElement ) ;
50+
51+ // console.log(keybinding);
52+
53+ // const e = new KeyboardEvent('keydown', event);
54+ // console.log('dispatching', e);
55+ // document.activeElement.dispatchEvent(e);
56+ // document.activeElement.dispatchEvent(new KeyboardEvent('keyup', event));
57+ }
58+
1559 async getElements ( selector : string ) : TPromise < IElement [ ] > {
1660 const query = document . querySelectorAll ( selector ) ;
1761 const result : IElement [ ] = [ ] ;
@@ -30,8 +74,12 @@ class WindowDriver implements IWindowDriver {
3074 }
3175}
3276
33- export async function registerWindowDriver ( client : IPCClient , windowId : number ) : TPromise < IDisposable > {
34- const windowDriver = new WindowDriver ( ) ;
77+ export async function registerWindowDriver (
78+ client : IPCClient ,
79+ windowId : number ,
80+ instantiationService : IInstantiationService
81+ ) : TPromise < IDisposable > {
82+ const windowDriver = instantiationService . createInstance ( WindowDriver ) ;
3583 const windowDriverChannel = new WindowDriverChannel ( windowDriver ) ;
3684 client . registerChannel ( 'windowDriver' , windowDriverChannel ) ;
3785
0 commit comments