Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9eaeb4db
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9eaeb4db
编写于
10月 22, 2020
作者:
S
SteVen Batten
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move menubars modifier key emitter to dom.ts
refs #109062
上级
791305d3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
125 addition
and
121 deletion
+125
-121
src/vs/base/browser/dom.ts
src/vs/base/browser/dom.ts
+122
-1
src/vs/base/browser/ui/menu/menubar.ts
src/vs/base/browser/ui/menu/menubar.ts
+3
-120
未找到文件。
src/vs/base/browser/dom.ts
浏览文件 @
9eaeb4db
...
...
@@ -10,12 +10,13 @@ import { IMouseEvent, StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import
{
TimeoutTimer
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
IDisposable
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
DisposableStore
,
IDisposable
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
FileAccess
,
RemoteAuthorities
}
from
'
vs/base/common/network
'
;
import
{
BrowserFeatures
}
from
'
vs/base/browser/canIUse
'
;
import
{
insane
,
InsaneOptions
}
from
'
vs/base/common/insane/insane
'
;
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
export
function
clearNode
(
node
:
HTMLElement
):
void
{
while
(
node
.
firstChild
)
{
...
...
@@ -1435,3 +1436,123 @@ export namespace WebFileSystemAccess {
return
false
;
}
}
type
ModifierKey
=
'
alt
'
|
'
ctrl
'
|
'
shift
'
;
export
interface
IModifierKeyStatus
{
altKey
:
boolean
;
shiftKey
:
boolean
;
ctrlKey
:
boolean
;
lastKeyPressed
?:
ModifierKey
;
lastKeyReleased
?:
ModifierKey
;
event
?:
KeyboardEvent
;
}
export
class
ModifierKeyEmitter
extends
Emitter
<
IModifierKeyStatus
>
{
private
readonly
_subscriptions
=
new
DisposableStore
();
private
_keyStatus
:
IModifierKeyStatus
;
private
static
instance
:
ModifierKeyEmitter
;
private
constructor
()
{
super
();
this
.
_keyStatus
=
{
altKey
:
false
,
shiftKey
:
false
,
ctrlKey
:
false
};
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
keydown
'
,
true
)(
e
=>
{
const
event
=
new
StandardKeyboardEvent
(
e
);
if
(
e
.
altKey
&&
!
this
.
_keyStatus
.
altKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
alt
'
;
}
else
if
(
e
.
ctrlKey
&&
!
this
.
_keyStatus
.
ctrlKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
ctrl
'
;
}
else
if
(
e
.
shiftKey
&&
!
this
.
_keyStatus
.
shiftKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
shift
'
;
}
else
if
(
event
.
keyCode
!==
KeyCode
.
Alt
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
else
{
return
;
}
this
.
_keyStatus
.
altKey
=
e
.
altKey
;
this
.
_keyStatus
.
ctrlKey
=
e
.
ctrlKey
;
this
.
_keyStatus
.
shiftKey
=
e
.
shiftKey
;
if
(
this
.
_keyStatus
.
lastKeyPressed
)
{
this
.
_keyStatus
.
event
=
e
;
this
.
fire
(
this
.
_keyStatus
);
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
keyup
'
,
true
)(
e
=>
{
if
(
!
e
.
altKey
&&
this
.
_keyStatus
.
altKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
alt
'
;
}
else
if
(
!
e
.
ctrlKey
&&
this
.
_keyStatus
.
ctrlKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
ctrl
'
;
}
else
if
(
!
e
.
shiftKey
&&
this
.
_keyStatus
.
shiftKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
shift
'
;
}
else
{
this
.
_keyStatus
.
lastKeyReleased
=
undefined
;
}
if
(
this
.
_keyStatus
.
lastKeyPressed
!==
this
.
_keyStatus
.
lastKeyReleased
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
this
.
_keyStatus
.
altKey
=
e
.
altKey
;
this
.
_keyStatus
.
ctrlKey
=
e
.
ctrlKey
;
this
.
_keyStatus
.
shiftKey
=
e
.
shiftKey
;
if
(
this
.
_keyStatus
.
lastKeyReleased
)
{
this
.
_keyStatus
.
event
=
e
;
this
.
fire
(
this
.
_keyStatus
);
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mousedown
'
,
true
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mouseup
'
,
true
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mousemove
'
,
true
)(
e
=>
{
if
(
e
.
buttons
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
window
,
'
blur
'
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
this
.
_keyStatus
.
lastKeyReleased
=
undefined
;
this
.
_keyStatus
.
altKey
=
false
;
this
.
_keyStatus
.
shiftKey
=
false
;
this
.
_keyStatus
.
shiftKey
=
false
;
this
.
fire
(
this
.
_keyStatus
);
}));
}
get
keyStatus
():
IModifierKeyStatus
{
return
this
.
_keyStatus
;
}
static
getInstance
()
{
if
(
!
ModifierKeyEmitter
.
instance
)
{
ModifierKeyEmitter
.
instance
=
new
ModifierKeyEmitter
();
}
return
ModifierKeyEmitter
.
instance
;
}
dispose
()
{
super
.
dispose
();
this
.
_subscriptions
.
dispose
();
}
}
src/vs/base/browser/ui/menu/menubar.ts
浏览文件 @
9eaeb4db
...
...
@@ -8,7 +8,6 @@ import * as browser from 'vs/base/browser/browser';
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
domEvent
}
from
'
vs/base/browser/event
'
;
import
{
StandardKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
EventType
,
Gesture
,
GestureEvent
}
from
'
vs/base/browser/touch
'
;
import
{
cleanMnemonic
,
IMenuOptions
,
Menu
,
MENU_ESCAPED_MNEMONIC_REGEX
,
MENU_MNEMONIC_REGEX
,
IMenuStyles
,
Direction
}
from
'
vs/base/browser/ui/menu/menu
'
;
...
...
@@ -16,7 +15,7 @@ import { ActionRunner, IAction, IActionRunner, SubmenuAction, Separator } from '
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
KeyCode
,
ResolvedKeybinding
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
Disposable
,
dispose
,
IDisposable
,
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
withNullAsUndefined
}
from
'
vs/base/common/types
'
;
import
{
asArray
}
from
'
vs/base/common/arrays
'
;
import
{
ScanCodeUtils
,
ScanCode
}
from
'
vs/base/common/scanCode
'
;
...
...
@@ -120,7 +119,7 @@ export class MenuBar extends Disposable {
this
.
setUnfocusedState
();
}));
this
.
_register
(
ModifierKeyEmitter
.
getInstance
().
event
(
this
.
onModifierKeyToggled
,
this
));
this
.
_register
(
DOM
.
ModifierKeyEmitter
.
getInstance
().
event
(
this
.
onModifierKeyToggled
,
this
));
this
.
_register
(
DOM
.
addDisposableListener
(
this
.
container
,
DOM
.
EventType
.
KEY_DOWN
,
(
e
)
=>
{
let
event
=
new
StandardKeyboardEvent
(
e
as
KeyboardEvent
);
...
...
@@ -860,7 +859,7 @@ export class MenuBar extends Disposable {
}
}
private
onModifierKeyToggled
(
modifierKeyStatus
:
IModifierKeyStatus
):
void
{
private
onModifierKeyToggled
(
modifierKeyStatus
:
DOM
.
IModifierKeyStatus
):
void
{
const
allModifiersReleased
=
!
modifierKeyStatus
.
altKey
&&
!
modifierKeyStatus
.
ctrlKey
&&
!
modifierKeyStatus
.
shiftKey
;
if
(
this
.
options
.
visibility
===
'
hidden
'
)
{
...
...
@@ -996,119 +995,3 @@ export class MenuBar extends Disposable {
};
}
}
type
ModifierKey
=
'
alt
'
|
'
ctrl
'
|
'
shift
'
;
interface
IModifierKeyStatus
{
altKey
:
boolean
;
shiftKey
:
boolean
;
ctrlKey
:
boolean
;
lastKeyPressed
?:
ModifierKey
;
lastKeyReleased
?:
ModifierKey
;
event
?:
KeyboardEvent
;
}
class
ModifierKeyEmitter
extends
Emitter
<
IModifierKeyStatus
>
{
private
readonly
_subscriptions
=
new
DisposableStore
();
private
_keyStatus
:
IModifierKeyStatus
;
private
static
instance
:
ModifierKeyEmitter
;
private
constructor
()
{
super
();
this
.
_keyStatus
=
{
altKey
:
false
,
shiftKey
:
false
,
ctrlKey
:
false
};
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
keydown
'
,
true
)(
e
=>
{
const
event
=
new
StandardKeyboardEvent
(
e
);
if
(
e
.
altKey
&&
!
this
.
_keyStatus
.
altKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
alt
'
;
}
else
if
(
e
.
ctrlKey
&&
!
this
.
_keyStatus
.
ctrlKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
ctrl
'
;
}
else
if
(
e
.
shiftKey
&&
!
this
.
_keyStatus
.
shiftKey
)
{
this
.
_keyStatus
.
lastKeyPressed
=
'
shift
'
;
}
else
if
(
event
.
keyCode
!==
KeyCode
.
Alt
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
else
{
return
;
}
this
.
_keyStatus
.
altKey
=
e
.
altKey
;
this
.
_keyStatus
.
ctrlKey
=
e
.
ctrlKey
;
this
.
_keyStatus
.
shiftKey
=
e
.
shiftKey
;
if
(
this
.
_keyStatus
.
lastKeyPressed
)
{
this
.
_keyStatus
.
event
=
e
;
this
.
fire
(
this
.
_keyStatus
);
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
keyup
'
,
true
)(
e
=>
{
if
(
!
e
.
altKey
&&
this
.
_keyStatus
.
altKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
alt
'
;
}
else
if
(
!
e
.
ctrlKey
&&
this
.
_keyStatus
.
ctrlKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
ctrl
'
;
}
else
if
(
!
e
.
shiftKey
&&
this
.
_keyStatus
.
shiftKey
)
{
this
.
_keyStatus
.
lastKeyReleased
=
'
shift
'
;
}
else
{
this
.
_keyStatus
.
lastKeyReleased
=
undefined
;
}
if
(
this
.
_keyStatus
.
lastKeyPressed
!==
this
.
_keyStatus
.
lastKeyReleased
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
this
.
_keyStatus
.
altKey
=
e
.
altKey
;
this
.
_keyStatus
.
ctrlKey
=
e
.
ctrlKey
;
this
.
_keyStatus
.
shiftKey
=
e
.
shiftKey
;
if
(
this
.
_keyStatus
.
lastKeyReleased
)
{
this
.
_keyStatus
.
event
=
e
;
this
.
fire
(
this
.
_keyStatus
);
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mousedown
'
,
true
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mouseup
'
,
true
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}));
this
.
_subscriptions
.
add
(
domEvent
(
document
.
body
,
'
mousemove
'
,
true
)(
e
=>
{
if
(
e
.
buttons
)
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
}
}));
this
.
_subscriptions
.
add
(
domEvent
(
window
,
'
blur
'
)(
e
=>
{
this
.
_keyStatus
.
lastKeyPressed
=
undefined
;
this
.
_keyStatus
.
lastKeyReleased
=
undefined
;
this
.
_keyStatus
.
altKey
=
false
;
this
.
_keyStatus
.
shiftKey
=
false
;
this
.
_keyStatus
.
shiftKey
=
false
;
this
.
fire
(
this
.
_keyStatus
);
}));
}
static
getInstance
()
{
if
(
!
ModifierKeyEmitter
.
instance
)
{
ModifierKeyEmitter
.
instance
=
new
ModifierKeyEmitter
();
}
return
ModifierKeyEmitter
.
instance
;
}
dispose
()
{
super
.
dispose
();
this
.
_subscriptions
.
dispose
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录