Skip to content

Commit bcede90

Browse files
committed
Move keyboard feature detection into caniuse.
1 parent f4a8c1d commit bcede90

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/vs/base/browser/canIUse.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import * as browser from 'vs/base/browser/browser';
77
import * as platform from 'vs/base/common/platform';
88

9+
export const enum KeyboardSupport {
10+
Always,
11+
FullScreen,
12+
None
13+
}
14+
915
/**
1016
* Browser feature we can support in current platform, browser and environment.
1117
*/
@@ -37,9 +43,17 @@ export const BrowserFeatures = {
3743
return true;
3844
})()
3945
},
40-
/*
41-
* Full Keyboard Support in Full Screen Mode or Standablone
42-
*/
43-
fullKeyboard: !!(<any>navigator).keyboard || browser.isSafari,
46+
keyboard: (() => {
47+
if (platform.isNative || browser.isStandalone) {
48+
return KeyboardSupport.Always;
49+
}
50+
51+
if ((<any>navigator).keyboard || browser.isSafari) {
52+
return KeyboardSupport.FullScreen;
53+
}
54+
55+
return KeyboardSupport.None;
56+
})(),
57+
4458
touch: 'ontouchstart' in window || navigator.maxTouchPoints > 0 || window.navigator.msMaxTouchPoints > 0
4559
};

src/vs/workbench/services/clipboard/browser/clipboardService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class BrowserClipboardService implements IClipboardService {
2727
newTextarea.style.visibility = 'false';
2828
newTextarea.style.height = '1px';
2929
newTextarea.style.width = '1px';
30+
newTextarea.setAttribute('aria-hidden', 'true');
31+
newTextarea.style.position = 'absolute';
32+
newTextarea.style.top = '-1000';
33+
newTextarea.style.left = '-1000';
3034
document.body.appendChild(newTextarea);
3135
newTextarea.value = text;
3236
newTextarea.focus();

src/vs/workbench/services/keybinding/browser/keybindingService.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { isArray } from 'vs/base/common/types';
4646
import { INavigatorWithKeyboard, IKeyboard } from 'vs/workbench/services/keybinding/browser/navigatorKeyboard';
4747
import { ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE } from 'vs/base/common/scanCode';
4848
import { flatten } from 'vs/base/common/arrays';
49-
import { BrowserFeatures } from 'vs/base/browser/canIUse';
49+
import { BrowserFeatures, KeyboardSupport } from 'vs/base/browser/canIUse';
5050

5151
interface ContributedKeyBinding {
5252
command: string;
@@ -241,7 +241,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
241241
this._register(browser.onDidChangeFullscreen(() => {
242242
const keyboard: IKeyboard | null = (<INavigatorWithKeyboard>navigator).keyboard;
243243

244-
if (!BrowserFeatures.fullKeyboard) {
244+
if (BrowserFeatures.keyboard === KeyboardSupport.None) {
245245
return;
246246
}
247247

@@ -352,15 +352,11 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
352352
}
353353

354354
private _assertBrowserConflicts(kb: Keybinding, commandId: string): boolean {
355-
if (!isWeb) {
355+
if (BrowserFeatures.keyboard === KeyboardSupport.Always) {
356356
return false;
357357
}
358358

359-
if (browser.isStandalone) {
360-
return false;
361-
}
362-
363-
if (browser.isFullscreen() && BrowserFeatures.fullKeyboard) {
359+
if (BrowserFeatures.keyboard === KeyboardSupport.FullScreen && browser.isFullscreen()) {
364360
return false;
365361
}
366362

0 commit comments

Comments
 (0)