More fixes for 24153

This commit is contained in:
Alex Dima 2017-04-28 17:10:19 +02:00 committed by VS Code
parent 634770b351
commit ccc0fa3c0b
4 changed files with 36 additions and 15 deletions

View file

@ -77,6 +77,10 @@ export interface IWindowConfiguration extends ParsedArgs {
userEnv: platform.IProcessEnvironment;
/**
* The physical keyboard is of ISO type (on OSX)
*/
isISOKeyboard?: boolean;
zoomLevel?: number;
fullscreen?: boolean;
highContrast?: boolean;

View file

@ -733,6 +733,7 @@ export class WindowsManager implements IWindowsMainService {
configuration.filesToCreate = filesToCreate;
configuration.filesToDiff = filesToDiff;
configuration.nodeCachedDataDir = this.environmentService.nodeCachedDataDir;
configuration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard();
return configuration;
}
@ -1331,10 +1332,12 @@ class KeyboardLayoutMonitor {
private _emitter: Emitter<boolean>;
private _registered: boolean;
private _isISOKeyboard: boolean;
private constructor() {
this._emitter = new Emitter<boolean>();
this._registered = false;
this._isISOKeyboard = this._readIsISOKeyboard();
}
public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable {
@ -1342,7 +1345,7 @@ class KeyboardLayoutMonitor {
this._registered = true;
nativeKeymap.onDidChangeKeyboardLayout(() => {
this._emitter.fire(this._isISOKeyboard());
this._emitter.fire(this._isISOKeyboard);
});
if (platform.isMacintosh) {
@ -1354,16 +1357,15 @@ class KeyboardLayoutMonitor {
// only after a NSEvent was handled.
//
// We therefore poll.
let prevValue: boolean = null;
setInterval(() => {
let newValue = this._isISOKeyboard();
if (prevValue === newValue) {
let newValue = this._readIsISOKeyboard();
if (this._isISOKeyboard === newValue) {
// no change
return;
}
prevValue = newValue;
this._emitter.fire(this._isISOKeyboard());
this._isISOKeyboard = newValue;
this._emitter.fire(this._isISOKeyboard);
}, 3000);
}
@ -1371,10 +1373,14 @@ class KeyboardLayoutMonitor {
return this._emitter.event(callback);
}
private _isISOKeyboard(): boolean {
private _readIsISOKeyboard(): boolean {
if (platform.isMacintosh) {
return nativeKeymap.isISOKeyboard();
}
return false;
}
public isISOKeyboard(): boolean {
return this._isISOKeyboard;
}
}

View file

@ -28,6 +28,7 @@ import gracefulFs = require('graceful-fs');
import { IPath, IOpenFileRequest } from 'vs/workbench/electron-browser/common';
import { IInitData } from 'vs/workbench/services/timer/common/timerService';
import { TimerService } from 'vs/workbench/services/timer/node/timerService';
import { KeyboardMapperFactory } from "vs/workbench/services/keybinding/electron-browser/keybindingService";
import { webFrame } from 'electron';
@ -35,6 +36,12 @@ import fs = require('fs');
gracefulFs.gracefulify(fs); // enable gracefulFs
export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
/**
* The physical keyboard is of ISO type (on OSX)
*/
isISOKeyboard?: boolean;
appRoot: string;
execPath: string;
@ -53,6 +60,8 @@ export function startup(configuration: IWindowConfiguration): TPromise<void> {
browser.setZoomLevel(webFrame.getZoomLevel());
browser.setFullscreen(!!configuration.fullscreen);
KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged(configuration.isISOKeyboard);
// Setup Intl
comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));

View file

@ -62,15 +62,17 @@ export class KeyboardMapperFactory {
}
public _onKeyboardLayoutChanged(isISOKeyboard: boolean): void {
this._isISOKeyboard = isISOKeyboard;
isISOKeyboard = !!isISOKeyboard;
if (this._initialized) {
this._setKeyboardData(nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
this._setKeyboardData(isISOKeyboard, nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
} else {
this._isISOKeyboard = isISOKeyboard;
}
}
public getKeyboardMapper(dispatchConfig: DispatchConfig): IKeyboardMapper {
if (!this._initialized) {
this._setKeyboardData(nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
this._setKeyboardData(this._isISOKeyboard, nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
}
if (dispatchConfig === DispatchConfig.KeyCode) {
// Forcefully set to use keyCode
@ -81,7 +83,7 @@ export class KeyboardMapperFactory {
public getCurrentKeyboardLayout(): nativeKeymap.IKeyboardLayoutInfo {
if (!this._initialized) {
this._setKeyboardData(nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
this._setKeyboardData(this._isISOKeyboard, nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
}
return this._layoutInfo;
}
@ -111,21 +113,21 @@ export class KeyboardMapperFactory {
public getRawKeyboardMapping(): nativeKeymap.IKeyboardMapping {
if (!this._initialized) {
this._setKeyboardData(nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
this._setKeyboardData(this._isISOKeyboard, nativeKeymap.getCurrentKeyboardLayout(), nativeKeymap.getKeyMap());
}
return this._rawMapping;
}
private _setKeyboardData(layoutInfo: nativeKeymap.IKeyboardLayoutInfo, rawMapping: nativeKeymap.IKeyboardMapping): void {
private _setKeyboardData(isISOKeyboard: boolean, layoutInfo: nativeKeymap.IKeyboardLayoutInfo, rawMapping: nativeKeymap.IKeyboardMapping): void {
this._layoutInfo = layoutInfo;
if (this._initialized && KeyboardMapperFactory._equals(this._rawMapping, rawMapping)) {
if (this._initialized && this._isISOKeyboard === isISOKeyboard && KeyboardMapperFactory._equals(this._rawMapping, rawMapping)) {
// nothing to do...
return;
}
this._initialized = true;
this._isISOKeyboard = isISOKeyboard;
this._rawMapping = rawMapping;
this._keyboardMapper = KeyboardMapperFactory._createKeyboardMapper(this._isISOKeyboard, KeyboardMapperFactory._isUSStandard(this._layoutInfo), this._rawMapping);
this._onDidChangeKeyboardMapper.fire();