Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
f111fei authored Jul 6, 2016
1 parent a620fa8 commit 36634c4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/vs/workbench/parts/html/browser/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {addDisposableListener, addClass} from 'vs/base/browser/dom';
import {addDisposableListener, addClass, EventType} from 'vs/base/browser/dom';
import {isLightTheme, isDarkTheme} from 'vs/platform/theme/common/themes';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';

declare interface WebviewElement extends HTMLElement {
src: string;
Expand Down Expand Up @@ -45,6 +47,19 @@ KeybindingsRegistry.registerCommandDesc({

type ApiThemeClassName = 'vscode-light' | 'vscode-dark' | 'vscode-high-contrast';

function isDefaultKeyboardEvent(e: KeyboardEvent): boolean {
let keyEvent = new StandardKeyboardEvent(e);
let keybinding = keyEvent.asKeybinding();
switch (keybinding) {
case KeyMod.CtrlCmd | KeyCode.KEY_C:
case KeyMod.CtrlCmd | KeyCode.KEY_V:
case KeyMod.CtrlCmd | KeyCode.KEY_X:
case KeyMod.CtrlCmd | KeyCode.KEY_A:
return true;
}
return false;
}

export default class Webview {

private _webview: WebviewElement;
Expand Down Expand Up @@ -93,6 +108,17 @@ export default class Webview {
this._webview.style.opacity = '';
return;
}
}),
addDisposableListener(this._webview, EventType.KEY_DOWN, (event: KeyboardEvent) => {
if (isDefaultKeyboardEvent(event)) {
event.stopImmediatePropagation();
}
}),
addDisposableListener(this._webview, EventType.DRAG_OVER, (event: DragEvent) => {
event.stopImmediatePropagation();
}),
addDisposableListener(this._webview, EventType.DROP, (event: DragEvent) => {
event.stopImmediatePropagation();
})
];

Expand Down

0 comments on commit 36634c4

Please sign in to comment.